XLoad
- Type
- Utility
- Category
- Raw file loader in MAC/65 assembler
- Author
- Petr Vicar
- Published in
- Flop (Czech disk magazine for 8-bit Atari), issue 8
- Year
- 1991
- Language
- 6502 assembly (MAC/65)
- Requirements
- MAC/65 assembler with the OSS macro files IOMAC.LIB and SYSEQU.M65, plus the author's SYSADR.M65 and MACRO.M65 (not included)
- Related
- MAC/65
About the program
XLoad does one simple job that DOS doesn't: it loads any file, whatever its format, into memory starting at an address you choose. A DOS binary load expects a file with load-address headers, but XLoad copies the raw bytes. That's handy for character sets, screen dumps, music data or a block of machine code saved without a header. The REMs give "XLOAD V1.0 5.1.1991" (5 January 1991), Petr Vicar of Rožnov pod Radhoštěm, and the purpose: Zavedení libovolného souboru na zadanou adresu, "loading any file to a given address". It appeared on the Czech disk magazine Flop, issue 8.
Czech text in the program
| Czech | English |
|---|---|
| Název souboru: | File name: |
| Na adresu (hexa > 21FF): | To address (hex, above $21FF): |
| 1. volná adresa: | First free address: |
| Blok č.: | Block no.: |
| I/O err n. | I/O error number |
| Výstup HEX | Hex output |
What you need
MAC/65, plus four include files. IOMAC.LIB (the OSS system I/O macros such as OPEN, BPUT, BGET, INPUT, CLOSE) and SYSEQU.M65 came with OSS's assembler. SYSADR.M65 and MACRO.M65 were the author's own files. They supplied, for example, EOUTCH and the HEXIN/HEXOUT macros, and they aren't part of this listing. To build it today you'll need to write small replacements for those: a routine that prints the accumulator as two hex digits, and one that reads a 4-digit hex number into HX/HX+1.
How it works
- Prints Název souboru:, INPUTs a filename and OPENs it on channel 1 for reading. On an error it prints the CIO status in hex and starts again.
- Asks for the load address in hex. The program itself sits at $2000, so the prompt warns you to choose something above $21FF.
- The loop at
VENcallsBGET 1,BUF,0. With a length of zero, CIO's "get bytes" command returns a single byte in the accumulator. Each byte is stored at (HX) and the pointer is incremented until CIO reports end-of-file (a negative status), at which point it jumps toKON. KONprints 1. volná adresa: with the next free address, so you know exactly where the data ends. Then it closes the file and returns withRTS, so you can start it with the run-at-address option of DOS and get back to the menu. (It has noPLAfor an argument count, so it isn't suitable for calling with BASIC'sUSR.)
Byte-at-a-time CIO calls are slow compared with one big block read, but the code stays tiny.
Listing
10 .OPT NO LIST
20 ;XLOAD V1.0 5.1.1991
30 ;
40 ;Petr Vicar, Roznov p.R
50 ;
60 ;Zavedeni libovolneho souboru
70 ;na zadanou adresu
80 ; .INCLUDE #D:SYSEQU.M65
90 .INCLUDE #D:IOMAC.LIB
100 .INCLUDE #D:SYSADR.M65
110 .INCLUDE #D:MACRO.M65
120 HX = $D4
130 POI = $D7
140 PR = $D8
150 CBL = $DA
155 NZ = $DC
160 ;
170 *= $2000
180 JMP ZAC
190 NAM .BYTE " Nazev souboru: "
195 KAM .BYTE " Na adresu ( hexa>21ff): "
196 SLUS .BYTE " 1.volna adresa: "
200 CB .BYTE " Blok c.: "
210 IOER .BYTE " I/O err n."
220 BUF *= *+15
230 ZAC
240 MOVA 1,CBL
250 BPUT 0,NAM,15
260 INPUT 0,BUF
270 OPEN 1,4,0,BUF
280 BPL DAL
290 STY HX
300 BPUT 0,IOER,10
310 LDA HX
320 JSR HO
330 JSR CROU
340 CLOSE 1
350 JMP ZAC
360 DAL BPUT 0,KAM,24
370 JSR HEXI
450 VEN BGET 1,BUF,0
460 BMI KON
470 ; LDA BUF
480 LDY #0
490 STA (HX),Y
500 INC HX
520 BNE VEN
530 INC HX+1
540 BNE VEN
610 KON
612 BPUT 0,SLUS,16
620 JSR HEXO
630 CLOSE 1
640 RTS
650 ;
660 ;
670 CROU LDA #$9B
680 JMP EOUTCH
690 ;
700 .OPT LIST
710 HEXO LDA HX+1 ;Vystup HEX
712 JSR HO
714 LDA HX
720 HO HEXOUT
730 .OPT NO LIST
740 HEXI LDY #5
750 HI HEXIN
760 .END
Credits
- Program listing: XLoad — program listing (Flop (Czech disk magazine for 8-bit Atari), issue 8) — Petr Vicar
- Gury's Atari 8-bit Forever — XLoad (listing) — Petr Vicar
- AtariAge forum — IOMAC.LIB operating in MADS (IOMAC.LIB identified as the OSS system I/O macros) — AtariAge forum members
