3 posts / 0 new
Last post
c128 machine language file manipulation

 I'm trying to write a machine language subroutine to manipulate a file, corrently working on open a sequential file and reading it contents into memory.
But I can't seem to get it to work, the following is what I have come up with so far, it is done using the Buddy 128 Development System.
10 save"@0:saver2",9
20 sys 4000
30 .org $1800
40 ;.dis
50 .mem
60 ;
70 setlfs = $ffba
80 setnam = $ffbd
90 open = $ffc0
100 close = $ffc3
110 chkin = $ffc6
120 ckout = $ffc9
130 clrchn = $ffcc
140 chrin = $ffcf
150 chrout = $ffd2
170 setbank = $ff68
180 mmureg = $ff00
220 ;
230 load1 lda #0
240 sta mmureg
250 lda #$fc
260 sta $d030; bank 15/slow speed
270 lda #10
280 ldx #<filename
290 ldy #>filename
300 jsr setnam; point to filename
310 ;
320 lda #0
330 tax
340 jsr setbank ;setbank to 0
350 lda #1
360 ldx #8
370 tay
380 jsr setlfs ;set logical number
390 jsr open ;open the file
400 ;
410 ldy #0
420 ldx #1
430 mloop jsr chkin
440 iny
450 sta $1900,y
460 jsr mloop ;stupid loop, get data and store below the program
470 rts
480 brk
490 ;
500 ;
510 ;
520 filename =*
530 .asc "manual,s,r"
540 fnamelen = *-filename
 
If I execute this from the moN I get an i/o error #3 (i believe it is a file not open error)
if anybody could point to what I'm doing wrong, or where I could go for more information (anything would be helpful right now)
 
 

Urk, I am way too rusty on

Urk, I am way too rusty on the file stuff, I only remember how the processor works, not the kernal and system calls.  Maybe reach out to Nybles and Bytes?  This would actually be a good topic for one of her videos.

YES I got it working, but I

YES I got it working, but I don't know if the problem is with VICE or me (probably me......maybe)
below is a compiled run the program; it will only read a sequential file on c64/128 in machine language
biggest changes are show errors from the command channel  and use logical file number 3 instead of 1 (because 1 and 2 would not work)

80: FFBA             SETLFS = $FFBA
90: FFBD             SETNAM = $FFBD
100: FFC0             OPEN = $FFC0
110: FFC9             CHKOUT = $FFC9
120: FFD2             CHROUT = $FFD2
130: FFC6             CHKIN = $FFC6
140: FFCF             CHRIN = $FFCF
150: FFC3             CLOSE = $FFC3
160: FFCC             CLRCHN = $FFCC
170: 0090             STATUS = $90
180: 00FB             ZP = $FB
190: FF68             SETBNK = $FF68
200: FF00             MMUREG = $FF00
;
220: 1800 20 07 18         JSR OPENFL
230: 1803 20 42 18         JSR READFL
240: 1806 60               RTS
;
250: 1807 A9 00       OPENFL LDA #0
270: 1809 8D 00 FF         STA MMUREG
280: 180C A9 0F            LDA #15
290: 180E A8               TAY
300: 180F A2 09            LDX #9
310: 1811 20 BA FF         JSR SETLFS
320: 1814 A9 00            LDA #0
330: 1816 20 BD FF         JSR SETNAM
340: 1819 20 C0 FF         JSR OPEN
350: 181C A9 03            LDA #3
360: 181E A8               TAY
370: 181F A2 09            LDX #9
380: 1821 20 BA FF         JSR SETLFS
390: 1824 AD C3 18         LDA BNKNUM
400: 1827 AE C4 18         LDX BNKFNM
410: 182A 20 68 FF         JSR SETBNK
420: 182D A9 0D            LDA #FNLENG
430: 182F A2 B6            LDX #<FILENM
440: 1831 A0 18            LDY #>FILENM
450: 1833 20 BD FF         JSR SETNAM
460: 1836 20 C0 FF         JSR OPEN
470: 1839 20 5A 18         JSR DERRCK
480: 183C A9 0F            LDA #15
490: 183E 20 C3 FF         JSR CLOSE
500: 1841 60               RTS
;
520: 1842 A2 03       READFL LDX #3
530: 1844 20 C6 FF         JSR CHKIN
;
550: 1847 20 CF FF    RDLOOP JSR CHRIN
560: 184A 20 D2 FF         JSR CHROUT
570: 184D A5 90            LDA STATUS
580: 184F F0 F6            BEQ RDLOOP
590: 1851 A9 03            LDA #3
600: 1853 20 C3 FF         JSR CLOSE
610: 1856 20 CC FF         JSR CLRCHN
620: 1859 60               RTS
;
640: 185A A2 0F       DERRCK LDX #15
650: 185C 20 C6 FF         JSR CHKIN
660: 185F A2 C6            LDX #<DSTAT
670: 1861 A0 18            LDY #>DSTAT
680: 1863 20 A1 18         JSR PRINTS
690: 1866 20 CF FF         JSR CHRIN
700: 1869 20 D2 FF         JSR CHROUT
710: 186C 0A               ASL
720: 186D 0A               ASL
730: 186E 0A               ASL
740: 186F 0A               ASL
750: 1870 8D C5 18         STA ERROR
760: 1873 20 CF FF         JSR CHRIN
770: 1876 20 D2 FF         JSR CHROUT
780: 1879 29 0F            AND #%00001111
790: 187B 0D C5 18         ORA ERROR
800: 187E 8D C5 18         STA ERROR
;
820: 1881 20 CF FF    MORE JSR CHRIN
830: 1884 C9 0D            CMP #13
840: 1886 F0 06            BEQ EXAMIT
850: 1888 20 D2 FF         JSR CHROUT
860: 188B 4C 81 18         JMP MORE
;
880: 188E 20 D2 FF    EXAMIT JSR CHROUT
890: 1891 AD C5 18         LDA ERROR
900: 1894 C9 21            CMP #$21
910: 1896 90 00            BCC ALLDONE
;
930: 1898 A9 0F       ALLDONE LDA #15
940: 189A 20 C3 FF         JSR CLOSE
950: 189D 20 CC FF         JSR CLRCHN
960: 18A0 60               RTS
;
980: 18A1 86 FB       PRINTS STX ZP
990: 18A3 84 FC            STY ZP+1
1000: 18A5 A0 00            LDY #0
;
1020: 18A7 B1 FB       PSLOOP LDA (ZP),Y
1030: 18A9 48               PHA
1040: 18AA 20 D2 FF         JSR CHROUT
1050: 18AD C8               INY
1060: 18AE 68               PLA
1070: 18AF C9 0D            CMP #13
1080: 18B1 D0 F4            BNE PSLOOP
1090: 18B3 60               RTS
;
;VARIABLES
;
1130: 18B4             BUFCTR =*
1140: 18B4 00 00            .WORD 0
1150: 18B6             FILENM =*
1160: 18C3                  .ASC "0:SAM.PLR,S,R"
1170: 000D             FNLENG = *-FILENM
1180: 18C3             BNKNUM =*
1190: 18C3 00               .BYT 00
1200: 18C4             BNKFNM =*
1210: 18C4 00               .BYT 00
1220: 18C5             ERROR =*
1230: 18C5 00               .BYT 00
1240: 18C6             DSTAT =*
1250: 18D2 0D               .ASC "DISK STATUS:" 13

*** SYMBOL TABLE ***
$FFBA SETLFS                     $FFBD SETNAM
$FFC0 OPEN                       $FFC9 CHKOUT
$FFD2 CHROUT                     $FFC6 CHKIN
$FFCF CHRIN                      $FFC3 CLOSE
$FFCC CLRCHN                     $0090 STATUS
$00FB ZP                         $FF68 SETBNK
$FF00 MMUREG                     $1807 OPENFL
$1842 READFL                     $1847 RDLOOP
$185A DERRCK                     $1881 MORE
$188E EXAMIT                     $1898 ALLDONE
$18A1 PRINTS                     $18A7 PSLOOP
$18B4 BUFCTR                     $18B6 FILENM
$000D FNLENG                     $18C3 BNKNUM
$18C4 BNKFNM                     $18C5 ERROR
$18C6 DSTAT                      
]1800-18D3
 

Log in or register to post comments