; vi:filetype=z80: fb_addr equ $4000 attr_addr equ $5800 ula_port equ $fe main: call init ld hl, fb_addr + 25 call draw_logo ld c, 4 ld b, 12 call calc_cell_addr ld hl, str_foobar call putstr .looptop: jr .looptop init: ; setup attributes ld hl, attr_addr ld a, $47 ld b, 24 .attry: ld c, 32 .attrx: ld (hl), a inc hl dec c jr nz, .attrx dec b jr nz, .attry ; clear screen ld hl, fb_addr xor a ld b, 192 .clry: ld c, 32 .clrx: ld (hl), a inc hl dec c jr nz, .clrx dec b jr nz, .clry ; set border out (ula_port), a ret ; expects X -> c, Y -> b, returns in de calc_cell_addr: push af sla b sla b ; change from blocks to pixels sla b ; construct low address byte -> e ld a, b ; start with Y sla a sla a and $e0 ; keep top 3 bits ld e, a ; move into e ld a, c ; a <- X and $1f ; keep low 5 bits or e ; combine with Y bits ld e, a ; move the result back to e ; construct high address byte -> d ld a, b ; start with Y again sra a sra a sra a and $18 ; keep bits 3 and 4 ld d, a ; keep it in d ld a, b ; grap Y one more time and $7 ; keep low 3 bits of Y in a or d ; combine with Y6-Y7 ld bc, fb_addr or b ; combine with high byte of fb address ld d, a ; move result back to d pop af ret ; hl: dest draw_logo: ld de, logo ld b, 16 .logoy: ld c, 7 push bc .logox: ld a, (de) ld (hl), a inc de inc l dec c jr nz, .logox ld bc, 7 sbc hl, bc inc h ld a, h and $e7 ld h, a and $7 jr nz, .skipinc ld a, l add $20 ld l, a .skipinc: pop bc dec b jr nz, .logoy ret ; de: dest ; a: char putchar: ; is it a digit? ld bc, glyph_0 sub '0' ret c cp 10 jr c, .common ; is it A-Z ? sub 'A'-'0' ret c cp 27 ret nc ld bc, glyph_a .common: push de push hl sla a sla a sla a ld h, 0 ld l, a add hl, bc ld c, 8 .chartop: ld a, (hl) ld (de), a inc d inc hl dec c jr nz, .chartop pop hl pop de ret ; de: dest ; hl: str putstr: xor a ld b, (hl) cp b jr z, .done ld a, b call putchar inc hl inc de jr putstr .done: ret ; de: dest ; a: number putbin8: ld b, 8 str_foobar asciiz 'FOOBAR 1234567890' include glyphs.inc include logo.inc