Pab Posted October 11, 2022 Share Posted October 11, 2022 My current project is being written in Action!, but a good chunk of the subroutines I will be using in it and as part of it are in machine language. To simplify the process of encoding machine language into Action! source, I wrote this quick-and-dirty utility I call OBJ2ACT. It was written and compiled in Fast Assembler as a relocatable SpartaDOS X command file. If there is call for it, I can rewrite parts of it to run under AtariDOS. I'm attaching an ATR file with the .COM file, source code, and a .MAN file. I'm also pasting the source code below for those who would rather cut-and-paste and assemble on their own than download. The program is in the public domain, free for use, modification, reimplementation, sharing, etc. * OBJ2ACT * Convert object files to Action! Source * By Pab Sungenis, 2022. Public Domain COMTAB smb 'COMTAB' PRINTF smb 'PRINTF' FPRINTF smb 'FPRINTF' U_GETPAR smb 'U_GETPAR' U_GETNUM smb 'U_GETNUM' FOPEN smb 'FOPEN' FGETC smb 'FGETC' FPUTC smb 'FPUTC' PUTC smb 'PUTC' FREAD smb 'FREAD' FWRITE smb 'FWRITE' FCLOSEAL smb 'FCLOSEAL' FCLOSE smb 'FCLOSE' U_SFAIL smb 'U_SFAIL' U_FAIL smb 'U_FAIL' U_XFAIL smb 'U_XFAIL' STATUS smb 'STATUS' srcstr equ $C6 deststr equ $C8 srcfile equ $CA destfile equ $CB datab equ $CC lnlen equ $CE scratch equ $D4 FHANDLE equ $760 FMODE equ $778 FAUX1 equ $782 FAUX2 equ $783 FAUX3 equ $784 FAUX4 equ $785 FAUX5 equ $786 SYSCALL equ $787 blk reloc main jmp start cpystr tya Copy one string into another. pha Adresses in srcstr and deststr cpylp lda (srcstr),y Bytes to copy in y sta (deststr),y dey bpl cpylp pla Bytes copied in A rts findext sta scratch See if there is an extension stx scratch+1 Y holds position if so $FF if not fx_lp lda (scratch),y cmp #'.' beq fx_out dey bmi fx_out jmp fx_lp fx_out rts ctrails lda _TRAILS Retrieve value from TRAILS sta scratch lda _TRAILS+1 sta scratch+1 ldy #0 lda (scratch),y rts ptrails pha Save new value in TRAILS lda _TRAILS sta scratch lda _TRAILS+1 sta scratch+1 ldy #0 pla sta (scratch),y rts writehex ldx destfile Write the hex value to file stx FHANDLE lda HexStr jsr FPUTC lda HexStr+1 jsr FPUTC lda HexStr+2 jsr FPUTC rts dta c'chngeex',b(0) chngeex lda #'.' Change the extension of a filespec sta (scratch),y tya Source in $D4/$D5, ext $D6/$D7 tax Y is position of dot in filespec adc scratch sta scratch Returns with new length in X. lda scratch+1 ASSUMES THREE CHARACTER EXTENSION adc #0 sta scratch+1 ldy #2 ce_lp lda (scratch+2),y sta (scratch),y inx dey bpl ce_lp ldy #3 lda #$9B sta (scratch),y rts getfname lda #$A0 jsr U_GETPAR clc bne gfout sec gfout rts fload lda datab Open file in COMFNAM ldx datab+1 sta FMODE jsr FOPEN lda FHANDLE ldx datab+1 sta srcfile-1,x clc rts finit jsr getfname bcs fi_err jsr ctrails sta sfnlen lda _COMFNAM ldx _COMFNAM+1 ldy sfnlen jsr findext bpl fini_0 lda _COMFNAM sta scratch lda _COMFNAM+1 sta scratch+1 lda _OBJ sta scratch+2 lda _OBJ+1 sta scratch+3 ldy sfnlen jsr chngeex txa stx sfnlen jsr ptrails fini_0 lda _COMFNAM sta srcstr Copy it to variable lda _COMFNAM+1 sta srcstr+1 lda _srcfn sta deststr lda _srcfn+1 sta deststr+1 ldy sfnlen iny jsr cpystr lda #4 Open for read sta datab ldx #1 stx datab+1 jsr fload bcc fini_2 fi_err lda #$9C jmp U_FAIL fini_2 jsr getfname bcc fini_3 lda _srcfn Copy source file name sta srcstr lda _srcfn+1 sta srcstr+1 lda _COMFNAM sta deststr lda _COMFNAM+1 sta deststr+1 ldy sfnlen iny jsr cpystr lda _COMFNAM ldx _COMFNAM+1 ldy sfnlen jsr findext lda _COMFNAM sta scratch lda _COMFNAM+1 sta scratch+1 lda _ACT Change its extension to ACT sta scratch+2 lda _ACT+1 sta scratch+3 jsr chngeex txa jsr ptrails fini_3 jsr ctrails sta dfnlen lda _COMFNAM sta srcstr lda _COMFNAM+1 sta srcstr+1 lda _destfn sta deststr lda _destfn+1 sta deststr+1 ldy dfnlen iny jsr cpystr lda #8 Open for write sta datab ldx #2 stx datab+1 jsr fload bcs fi_err ldx srcfile Check the file header stx FHANDLE We want either SpartaDOS FA,FF jsr FGETC Or AtariDOS FF,FF pha jsr FGETC cmp #$FF bne fi_bad pla cmp #$FA beq fi_ok cmp #$FF beq fi_ok fi_bad pla jmp fi_err fi_ok rts mkhex ldx #2 Hex representation of byte lda datab mkh_lp pha and #$0f clc adc #$30 Numbers are from $30 to $39 cmp #$3a bcc mkh_0 clc adc #$07 Make it a letter mkh_0 sta HexStr,x pla lsr @ lsr @ lsr @ lsr @ dex bne mkh_lp lda #'$' sta HexStr,x rts gethdr clc ldx srcfile stx FHANDLE jsr FGETC Get first byte. cpx #$FF EOF? bne gh_get1 If not, continue. jmp endprog If so, end. gh_bad sec rts gh_get1 sta bstart Save the starting address jsr FGETC cpx #$FF beq gh_bad sta bstart+1 cmp #$FF Is the second byte $FF? bne getadds If not, it's an address. lda bstart cmp #$FA Sparta fixed block? beq gethdr If so, pull the next address cmp #$FF beq gethdr Atari fixed block? Do same. getadds jsr FGETC bpl gh_get4 jmp gh_bad Error reading from file. gh_get4 sta bend jsr FGETC bpl gh_get5 jmp gh_bad gh_get5 sta bend+1 We have the ending address. gh_math sec lda bend sbc bstart sta seglen lda bend+1 sbc bstart+1 sta seglen+1 inc seglen Get the segment length. bne gh_out inc seglen+1 gh_out jsr PRINTF dta c'Module from %4x to %4x (%d bytes).',b($9B,$0) dta v(bstart),v(bend),v(seglen) clc Success rts writeEOL lda #$9B ldx destfile stx FHANDLE jsr FPUTC rts writesp lda #$20 ldx destfile stx FHANDLE jsr FPUTC rts mainloop ldx srcfile stx FHANDLE jsr FGETC Get byte from source file cpx #$FF beq ml_out EOF? sta datab jsr mkhex Convert to hex string jsr writehex Write it. jsr writesp dec lnlen How many bytes in this line? bne ml_0 If 8, start next line. jsr writeEOL jsr writesp lda #8 sta lnlen ml_0 lda cnter Are we done with this block? cmp bend bne ml_1 lda cnter+1 cmp bend+1 beq ml_out ml_1 inc cnter bne mainloop inc cnter+1 bne mainloop ml_out rts vtrap dta v(trap) trap cmp #$9C bne trap_0 jsr PRINTF dta b($9B),c'Usage:',b($9b,$9B) dta c'OBJ2ACT sourcefile[.ext] [destfile[.ext]]',b($9b) dta b($9b,0) lda #0 trap_0 sta STATUS jmp FCLOSEAL start lda vtrap ldx vtrap+1 jsr U_SFAIL jsr finit jsr PRINTF dta b($9B),c'Encoding %s to %s',b($9B,$00) dta v(srcfn),v(destfn) st_lp jsr gethdr bcs endprog ldx destfile stx FHANDLE jsr FPRINTF dta c';%4x-%4x (%d bytes).',b($9B,$0) dta v(bstart),v(bend),v(seglen) lda #'[' jsr FPUTC lda #8 sta lnlen lda bstart sta cnter lda bstart+1 sta cnter+1 jsr mainloop lda #']' ldx destfile stx FHANDLE jsr FPUTC lda #$9B jsr FPUTC jsr FPUTC ldx srcfile stx FHANDLE jmp st_lp endprog jsr FCLOSEAL jsr U_XFAIL lda #1 sta STATUS rts _srcfn dta v(srcfn) _destfn dta v(destfn) _sfnlen dta v(sfnlen) _dfnlen dta v(dfnlen) _COMFNAM dta v(COMTAB+$21) _TRAILS dta v(COMTAB+$1A) objex dta c'OBJ' actex dta c'ACT' _obj dta v(objex) _act dta v(actex) srcfn equ * destfn equ srcfn+30 sfnlen equ destfn+30 dfnlen equ sfnlen+1 bstart equ dfnlen+1 bend equ bstart+2 headr1 equ bend+2 headr2 equ headr1+2 cnter equ headr2+2 HexStr equ cnter+2 seglen equ HexStr+1 blk empty 78 main blk update addresses blk update symbols end obj2act.atr 3 3 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.