10REM (C) Edinburgh Software Products 20REM This software is released into the public domain. 30OSARGS = &FFDA 40OSFILE = &FFDD 50OSBYTE = &FFF4 60OSWRCH = &FFEE 70OSASCI = &FFE3 80OSRDCH = &FFE0 90 100size = &40 110zp = &70 120from = &74 130to = &76 140 150CodeSize = &300 160CodeAddr = &3000-CodeSize 170DIM Code CodeSize-1 180 190FOR PASS = 4 TO 6 STEP 2 200O%=Code 210P%=CodeAddr 220[OPT PASS 230.Entry 240\ Start up in MODE 7 so that display is not corrupted 250 Lda #22: Jsr OSWRCH 260 Lda #7: Jsr OSWRCH 270\ Get the rest of the command line 280 Lda #1 290 Ldx #zp 300 Ldy #0 310 Jsr OSARGS 320\ Copy the file name into private space 330 Ldy #&FF 340 Ldx #0 350.skip_spaces 360\ Skip leading spaces 370 Iny 380 Lda (zp),Y 390 Cmp #32 400 Beq skip_spaces 410 Cmp #&0D 420 Beq NoFileName 430.copy_filename 440\ Copy the filename itself 450 Lda (zp),Y 460 Sta filename,X 470 Inx 480 Iny 490 Cmp #ASC(" ") 500 Beq slot_found 510\ Stop on space - slot no. follows 520 Cmp #&0D 530 Bne copy_filename 540\ RAM slot not specified, must find one 550 Ldx #&FF 560.grope_RAM 570 Inx 580 Jsr check_RAM 590 Cmp #1 600 Bne LastSlotTest:Jmp found_RAM:.LastSlotTest 610 Cpx #15 620 Bne grope_RAM 630 BRK: EQUB 3: EQUS "No RAM fitted - Write Disabled?": EQUB 0 640.NoFileName 650 BRK:EQUB 10:EQUS "Syntax: *ROMLOAD File 0 (or 1, E, or F)":EQUB 0 660.slot_found 670\ Slot number follows after possible spaces 680 Lda (zp),Y 690 Iny 700 Cmp #32 710 Beq slot_found 720 730 Sec: Sbc #ASC("0") 740 Bmi syntax_err 750 Cmp #10: Bcc got_digit 760 Sbc #7 770 Cmp #16: Bcs syntax_err 780 Cmp #10: Bcc syntax_err 790 800.got_digit 810 Tax 820 Jsr check_RAM 830 Cmp #1 840 Beq found_RAM 850 860 BRK: EQUB 10: EQUS "That slot is not RAM": EQUB 0 870.syntax_err 880 BRK: EQUB 9: EQUS "Bad ROM number - should be 0, 1, E, or F":EQUB 0 890.found_RAM 900 Stx ramslt 910 Lda #&05 920 Ldx #CB MOD 256 930 Ldy #CB DIV 256 940 Jsr OSFILE 950 Lda #0 960 Sta CB+2 970 Sta CB+4 980 Sta CB+5 990 Sta CB+6 1000 Lda #&30 1010 Sta CB+3 1020 Lda #&FF 1030 Ldx #CB MOD 256 1040 Ldy #CB DIV 256 1050 Jsr OSFILE 1060 Cmp #1 1070 JMP Load_ROM_emulator \ Should be BNE - but some filing systems have bug 1080 BRK: EQUB 1: EQUS "Failed to load file": EQUB 0 1090.Read_failed 1100 Jmp rd_fail 1110.Load_ROM_emulator 1120 PHP:SEI 1130 Lda &F4 1140 Sta Old_latch 1150 Lda ramslt 1160 Sta &F4 1170 Sta &FE30 1180 Ldy #0 1190 Lda #&30: Sta from+1 1200 Lda #&00: Sta from+0 1210 Lda #&80: Sta to+1 1220 Lda #&00: Sta to+0 1230.Load_up 1240 Lda (from),Y 1250 Sta (to),Y 1260 Inc from 1270 Bne from_1 1280 Inc from+1 1290.from_1 1300 Inc to 1310 Bne to_1 1320 Inc to+1 1330.to_1 1340 Lda from+1 1350 Cmp #&30+size 1360 Bne Load_up 1370 Lda #&30: Sta from+1 1380 Lda #&00: Sta from+0 1390 Lda #&80: Sta to+1 1400 Lda #&00: Sta to+0 1410.Check_up 1420 Lda (from),Y 1430 Cmp (to),Y 1440 Bne Read_failed 1450 Inc from 1460 Bne from_2 1470 Inc from+1 1480.from_2 1490 Inc to 1500 Bne to_2 1510 Inc to+1 1520.to_2 1530 Lda from+1 1540 Cmp #&30+size 1550 Bne Check_up 1560 Lda Old_latch 1570 Sta &F4 1580 Sta &FE30 1590 Plp 1600 Jsr pstring: EQUS "Loaded into slot ": EQUB 0 1610 Lda ramslt 1620 Cmp #10 1630 bcc not_digit 1640 Adc #6 \ Carry set 1650.not_digit 1660 Adc #ASC("0") 1670 jsr OSWRCH 1680 Jsr pstring 1690 EQUS ". Set write protect" 1700 EQUB 13: EQUS "and press any key to continue" 1710 EQUB 7: EQUB 0 1720 Jsr OSRDCH 1730 Lda #&7F 1740 Sta &FE4E 1750 Jmp (&FFFC) 1760.rd_fail 1770 Lda #&80: Sta to+1 1780 Lda #&00: Sta to+0 1790.Zero_out 1800 Lda #&00 1810 Sta (to),Y 1820 Inc to 1830 Bne to_3 1840 Inc to+1 1850.to_3 1860 Lda to+1 1870 Cmp #&80+size 1880 Bne Zero_out 1890 Lda Old_latch 1900 Sta &F4 1910 Sta &FE30 1920 PLP 1930 BRK: EQUB 4: EQUS "Read-back error in RAM": EQUB 0 1940.check_RAM 1950 Php: Sei 1960 Lda &F4: Sta Old_latch 1970 Stx &F4: Stx &FE30 1980 Lda &8000 1990 Eor #&FF 2000 Sta &8000 2010 Eor #&FF 2020 Sta &8001 2030 Eor #&FF 2040 Cmp &8000 2050 Beq is_RAM 2060 lda #0 2070 Jmp check_ret 2080.is_RAM 2090 lda #1 2100.check_ret 2110 pha 2120 Lda Old_latch: Sta &F4: Sta &FE30 2130 pla 2140 Plp: Rts 2150.pstring 2160 tsx 2170 inx: lda &100,X: sta from 2180 inx: lda &100,X: sta from+1 2190 ldy #0 2200.pstrloop 2210 inc from 2220 bne noinc_3 2230 inc from+1 2240.noinc_3 2250 lda (from),Y 2260 beq pstrdone 2270 jsr OSASCI 2280 jmp pstrloop 2290.pstrdone 2300 lda from+1 2310 sta &100,X 2320 dex 2330 lda from 2340 sta &100,X 2350 rts 2360.Old_latch 2370 EQUB 0 2380.ramslt 2390 EQUB 15 2400.filename 2410 EQUS " ":EQUB 13 2420.CB 2430 EQUW filename 2440 EQUD &FFFF3000 2450 EQUD 0 2460 EQUD 0 2470 EQUD 0 2480] 2490NEXT 2500PRINT "Assembled OK." 2510OSCLI("SAVE $.ROMLOAD "+STR$~Code+" "+STR$~O%+" "+STR$~(&FFFF0000+CodeAddr)+" "+STR$~(&FFFF0000+Entry)) 2520END