; rom2hex.as - Dump a ROM file in Intel HEX format ; Copyright (C) 2001 ag0ny@ag0ny.com ; v0.01 Initial release BDOS equ 005h ; BDOS entry point _STROUT equ 009h ; String output _FOPEN equ 00Fh ; Open file [FCB] _FCLOSE equ 010h ; Close file [FCB] _RDSEQ equ 014h ; Sequential read [FCB] _SETDTA equ 01ah ; Set Disk Transfer Address FCB1 equ 05ch ; First unopened FCB RECLEN equ 010h ; Intel HEX record length LF equ 00ah ; Line feed CR equ 00dh ; Carriage return ; system - execute MSX-DOS(2) function ; system macro function ld c,function call BDOS endm ; *********************** ; * program starts here * ; *********************** ; start: ld (STACK),sp ; save original stack pointer ld de,DTA system _SETDTA ld de,FCB1 system _FOPEN or a ; error opening the input file? jr z,l01 ld de,MSG00 ; file not found, exit jp exit l01: ld hl,00100h ; *** MAKE THIS READ FROM CMDLINE! *** ld (OFFSET),hl read: ld hl,DTA ld (DTAOFF),hl ld de,FCB1 system _RDSEQ push af ; check later for EOF ld c,8 ; print 8 records (= DTA = 128 bytes) l03: push bc call record pop bc dec c jr nz,l03 pop af or a jr z,read ld de,ENDRECORD ; print terminator system _STROUT ld de,FCB1 system _FCLOSE ld de,MSG01 call exit ; exit program returning a message pointed by DE ; exit: system _STROUT ld sp,(STACK) ret record: ld hl,0 ; reset checksum ld (SUM),hl ld a,RECLEN ; HEX record length ld de,PRINTBUF+1 call updatesum call hex ld a,(OFFSET+1) ; ROM offset call updatesum call hex ld a,(OFFSET) call updatesum call hex xor a ; type of record call updatesum ; now this doesn't do anything. maybe ; will be needed in future versions call hex ; start dumping one record of data from here ld hl,(DTAOFF) ld c,RECLEN l02: ld a,(hl) push hl push bc call updatesum call hex pop bc pop hl inc hl dec c jr nz,l02 ld (DTAOFF),hl ; update offset into DTA ld hl,(OFFSET) ; update ROM offset ld b,0 ld c,RECLEN add hl,bc ld (OFFSET),hl ; compute checksum ld a,(SUM) ; modulo 256 of sum (=low byte) ld c,a ld b,0 ld hl,00100h or a ; CY -> 0 sbc hl,bc ld a,l call hex ex de,hl ; print CRLF+"$" ld (hl),10 inc hl ld (hl),13 inc hl ld (hl),"$" ex de,hl ld de,PRINTBUF ; print record system _STROUT ret ; updatesum - add value in A to sum for checksum ; updatesum: ld hl,(SUM) ; update sum ld b,0 ld c,a add hl,bc ld (SUM),hl ret ; hex - print hexadecimal value of A ; input: A value ; DE string destination ; modifies: AF,HL,BC,DE ; hex: ld hl,HEXDIGIT push af and 011110000b ; high nibble rlca rlca rlca rlca ld c,a ld b,0 add hl,bc ld a,(hl) ex de,hl ld (hl),a ex de,hl inc de pop af ld hl,HEXDIGIT and 000001111b ; low nibble ld c,a add hl,bc ld a,(hl) ex de,hl ld (hl),a ex de,hl inc de ret ; ******** ; * data * ; ******** ; MSG00: defb "Can't open input file, exiting.$" MSG01: defb "ROM file decoded, exiting.$" ENDRECORD: defb ":00000001FF",CR,"$" HEXDIGIT: defb "0123456789ABCDEF" OFFSET: defs 2 ; ROM address STACK: defs 2 ; Original stack pointer SUM: defs 2 ; Sum for checksum DTAOFF: defs 2 ; Offset inside the DTA DTA: defs 128 ; Disk Transfer Address PRINTBUF: defb ":10aaaa00ddddddddddddddddddddddddddddddddcc",CR,"$"