;; the idea is to make a small binary file : ;; the library routines are far from optimal .globl _my_memcpy _my_memcpy: push ix ld ix,#0 add ix,sp ld l,4(ix) ld h,5(ix) ld e,6(ix) ld d,7(ix) ld c,8(ix) ld b,9(ix) ldir ; (DE++) <- (HL++), BC-- pop ix ret ;; this is for a simple text mode screen where the attribute ;; memory is used to store ASCII characters. .globl _cls _cls: ld a, #0x20 ld b, #0 ld hl, #0x5800 l1: ld (hl),a inc hl djnz l1 l2: ld (hl),a inc hl djnz l2 l3: ld (hl),a inc hl djnz l3 ret .globl _print_hex .globl _print_dec .globl calc_screen_addr _print_hex: push ix ld ix,#0 add ix,sp ld l,4(ix) ld h,5(ix) pop ix push bc push hl call calc_screen_addr ex de,hl ; DE now points to screen addr pop hl call Num2Hex pop bc ret _print_dec: push ix ld ix,#0 add ix,sp ld l,4(ix) ld h,5(ix) pop ix push bc push hl call calc_screen_addr ex de,hl ; DE now points to screen addr pop hl call Num2Dec pop bc ret ;;;;; general library routines - very effecient implementations ;; taken from various places, public domain AFAIK ;Input: HL = number to convert, DE = location of ASCII string ;Output: ASCII string at (DE) Num2Dec: ld bc,#-10000 call Num1 ld bc,#-1000 call Num1 ld bc,#-100 call Num1 ld c,#-10 call Num1 ld c,#-1 Num1: ld a,#0x2f ;('0'-1) Num2: inc a add hl,bc jr c,Num2 sbc hl,bc ld (de),a inc de ret ;Hexadecimal conversion operates directly on nibbles and takes advantage of nifty DAA trick. ;Input: HL = number to convert, DE = location of ASCII string ;Output: ASCII string at (DE) Num2Hex: ld a,h call Num11 ld a,h call Num22 ld a,l call Num11 ld a,l jr Num22 Num11: rra rra rra rra Num22: or #0xF0 daa add a,#0xA0 adc a,#0x40 ld (de),a inc de ret ;;; restore the CPU state from the SNA header. ;; based on "demfir" code .globl _restore_from_SNA ;EIROM: ei ; ; ret EIROM = 0x51 ; we have it at a known location to switch to flash ;; SNASTART = 0x2000 ; .globl _block_buffer ;; SNASTART = _block_buffer ; ;SNASTART: ; just for testing ; .byte 0x3f, 0x58, 0x27, 0x33, 0xd8, 0x50, 0x00, 0x21, 0xff, 0x00 ; .byte 0x5b, 0x00, 0x00, 0x00, 0x00, 0x3a, 0x5c, 0x06 ,0xd6, 0x00 ; .byte 0x53, 0x6d, 0xff, 0x52, 0x5f, 0x01, 0x02 _restore_from_SNA: ld bc, #0x7ffd ld a, #0x10 ; map in the 48K ROM out (c),a ld a,(_block_buffer+19) bit 2,a ld hl,#EIROM jr nz,SNAEI inc hl ; point to ret if iff bit not set SNAEI: ld (SNARUN+1),hl ld hl,#_block_buffer+26 ; border color ld a,(hl) out (254),a dec hl ld a,(hl) im 0 or a jr z,IMSNA im 1 dec a jr z,IMSNA im 2 IMSNA: ld hl,#_block_buffer ld a,(hl) ld i,a inc hl ld sp,hl pop hl pop de pop bc pop af exx ex af,af' pop hl pop de pop bc pop iy pop ix pop af ld r,a pop af ld sp,(_block_buffer+23) ;; jp SNARUN SNARUN: jp 0000 ; patched to jp EIROM