Author Topic: Small-C help needed  (Read 4706 times)

0 Members and 1 Guest are viewing this topic.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.900
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1113
  • Likes Given: 1879
Re: Small-C help needed
« Reply #25 on: 14:35, 16 July 13 »
If anyone has some Small-C code which passes values from variables into Inline Assembly, it would help me out greatly.  ;D

All I have is this oscall routine, which I think even with the comments I'll be confused, but here it is anyway:

Code: [Select]
oscall(adr,regpack)
int adr;
int *regpack; /* af,hl,de,bc */
{
#asm
 pop bc  ; ret
 pop de  ; regs
 pop hl  ; adr
 push hl
 push de
 push bc

 ld (031h),hl  ; rst 30h: user
 ld a,0c3h
 ld (030h),a

 push de
 ex (sp),ix

 ld l,(ix+0)
 ld h,(ix+1)
 push hl
 pop af

 ld l,(ix+2)
 ld h,(ix+3)
 ld e,(ix+4)
 ld d,(ix+5)
 ld c,(ix+6)
 ld b,(ix+7)

 ex (sp),ix

 rst 30h      ; execute os-call

 ex (sp),ix

 ld (ix+2),l
 ld (ix+3),h
 push af
 pop  hl
 ld (ix+0),l
 ld (ix+1),h
 ld (ix+4),e
 ld (ix+5),d
 ld (ix+6),c
 ld (ix+7),b

 pop de
 JP  CCSXT   ;move A to HL & sign extend

#endasm
}
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline TFM

  • Visit the mysteries of the CPC at www.futureos.de
  • Supporter
  • 6128 Plus
  • *
  • Posts: 9.899
  • Country: aq
  • Space Chicken for FutureOS is free!
    • index.php?action=treasury
    • FutureOS - The revolution on CPC!
  • Liked: 1981
  • Likes Given: 4650
Re: Small-C help needed
« Reply #26 on: 21:54, 16 July 13 »
Ok, so if I read the handbook correctly, there is no character set in MODE 0, so I cannot use RAMCHAR and will have to make a graphical routine to display it as a graphic.
That's right. Mode 0 characters are too big to make any sense IMHO.
 
If anyone has some Small-C code which passes values from variables into Inline Assembly, it would help me out greatly.  ;D
You can take a look at the Assembler part of FIOLIB to see how it passes variables over. May it helps a bit. [nb]See files RUNC-64K.MAX and RUNC-X16.MAX on DSK. Please use VaraDOS, VDOS or X-DDOS for reading DSK in Vortex Format.[/nb]
http://futureos.cpc-live.com/files/FIO.zip
« Last Edit: 22:00, 16 July 13 by TFM/FS »
TFM of FutureSoft
Also visit the CPC and Plus users favorite OS: FutureOS - The Revolution on CPC6128 and 6128Plus

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.900
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1113
  • Likes Given: 1879
Re: Small-C help needed
« Reply #27 on: 12:01, 17 July 13 »
You can take a look at the Assembler part of FIOLIB to see how it passes variables over. May it helps a bit. [nb]See files RUNC-64K.MAX and RUNC-X16.MAX on DSK. Please use VaraDOS, VDOS or X-DDOS for reading DSK in Vortex Format.[/nb]

The assembly code hasn't really given me any real insight unfortunately, I know that to use the oscall routine an array called regs[number] has been setup to pass values to that oscall. there's examples of this which I posted on the 1st page of this thread, along with the oscall routine, the different numbers in the regs array reflect the registers used (af,hl,de & bc I think in that order from 0 to 3). Obviously the oscall routine has 2 parameters, the first being the address to call the external routine - what the oscall routine does here is setup a jump routine by poking address 30h with c3 and HL which goes into 31 & 32 is obviously the address for the call, so when it's ready to be called - rst 30h.
What I don't get with the oscall routine is all the POPping - BC,DE,HL followed by PUSHing HL,DE & BC, DE gets PUSHed again after the address routine has been setup. ex (sp),ix is then applied - I'm not sure what that means, ex is an exchange instruction, I'm not sure why it has to exchange with the stack pointer - the contents of the stack pointer would go into the Index Register I presume and then it gets switched over again once the locations & contents of the Index Registers have been placed into their rightful registers.

The routine I wanted to write to pass values from small-c to Assembly is a bit different, in my case I want to designate the xpos & ypos in order to use those to plot that image to screen. oscall is a bit different in that it has to accommodate whatever gets thrown back at it, so anything which uses A,HL,DE or BC probably has to go through all that POPing & PUSHing regardless. My routine only has to worry about DE & HL (presumably) which would have DE & HL, the address of the image I'm doing internally, cause it would be easier to feed the colour data of the image from some M/C data, I could possibly use oscall to call the routines, but I thought it would be faster to keep it all Assembly and call the address from the routine itself.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.900
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1113
  • Likes Given: 1879
Re: Small-C help needed
« Reply #28 on: 13:09, 18 July 13 »
I had another look at how my  generated Small-C code into Assembly would work by passing the values for use into an Assembly routine and it looks as if Register Set is fixed into certain positions, which is how the oscall() routine functions by the looks of it, though I haven't been able to nut out how it would help me in my routine.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3