diff --git a/desktop/asm.cfg b/desktop/asm.cfg index 9287012..07f4d90 100644 --- a/desktop/asm.cfg +++ b/desktop/asm.cfg @@ -5,7 +5,9 @@ FEATURES { } MEMORY { MAIN: file = %O, define = yes, start = %S, size = $20000; # 128k; custom loader handles details + BSS: file = "", start = $0000, size = $10000; } SEGMENTS { CODE: load = MAIN, type = rw; + BSS: load = BSS, type = bss; } diff --git a/desktop/mgtk.s b/desktop/mgtk.s index 49bdc93..c81619d 100644 --- a/desktop/mgtk.s +++ b/desktop/mgtk.s @@ -331,7 +331,7 @@ jump_table: ;; Initialization Calls .addr StartDeskTopImpl ; $1D StartDeskTop .addr StopDeskTopImpl ; $1E StopDeskTop - .addr SetUserHookImpl ; $1F SetUserHook + .addr SetUserHookImpl ; $1F SetUserHook .addr AttachDriverImpl ; $20 AttachDriver .addr ScaleMouseImpl ; $21 ScaleMouseImpl .addr KeyboardMouse ; $22 KeyboardMouse @@ -3400,7 +3400,7 @@ do_draw: sta clipped_top tay - ldx #15*shifted_draw_line_size + ldx #(max_font_height-1)*shifted_draw_line_size sec : lda glyph_row_lo,y @@ -3415,7 +3415,7 @@ do_draw: bpl :- ldy clipped_top - ldx #15*unshifted_draw_line_size + ldx #(max_font_height-1)*unshifted_draw_line_size sec : lda glyph_row_lo,y sta unshifted_draw_linemax+1,x @@ -3602,7 +3602,7 @@ advance_byte: bne :+ jmp first_blit -: bmi L5C84 +: bmi next_byte dec width_bytes bne unmasked_blit jmp last_blit @@ -3631,8 +3631,10 @@ unmasked_blit_linemax: .endrepeat -L5C84: bit current_mapwidth +next_byte: + bit current_mapwidth bpl text_ndbm + lda vid_page eor #1 tax @@ -3659,7 +3661,7 @@ first_blit: beq single_byte_blit jsr masked_blit - jmp L5C84 + jmp next_byte single_byte_blit: ; a single byte length blit; i.e. start and right_masks_table,x ; and end bytes are the same @@ -4016,7 +4018,7 @@ ycoord: .word 0 mouse_state: mouse_x: .word 0 mouse_y: .word 0 -mouse_status: .byte 0 +mouse_status: .byte 0 ; bit 7 = is down, bit 6 = was down, still down mouse_scale_x: .byte $00 mouse_scale_y: .byte $00 @@ -4030,53 +4032,80 @@ mouse_hook: cursor_hotspot_x: .byte $00 cursor_hotspot_y: .byte $00 -L6004: .byte $00 -L6005: .byte $00 -L6006: .byte $00 -L6007: .byte $00 -L6008: .byte $00 -L6009: .byte $00 -L600A: .byte $00 -L600B: .byte $00,$00,$00,$00,$00,$00,$00,$00 - .byte $00,$00,$00,$00,$00,$00,$00,$00 - .byte $00,$00,$00,$00,$00,$00,$00,$00 - .byte $00,$00,$00,$00,$00,$00,$00,$00 - .byte $00,$00,$00,$00 -L602F: .byte $00,$00,$00,$00 -L6033: .byte $00,$00,$02,$00 - .byte $06,$00,$0E,$00,$1E,$00,$3E,$00 - .byte $7E,$00,$1A,$00,$30,$00,$30,$00 - .byte $60,$00,$00,$00,$03,$00,$07,$00 - .byte $0F,$00,$1F,$00,$3F,$00,$7F,$00 - .byte $7F,$01,$7F,$00,$78,$00,$78,$00 - .byte $70,$01,$70,$01,$01,$01 -L6065: .addr L6033 -L6067: lda #$FF +cursor_mod7: + .res 1 + +cursor_bits: + .res 3 +cursor_mask: + .res 3 + +cursor_savebits: + .res 3*MGTK::cursor_height ; Saved 3 screen bytes per row. + +cursor_data: + .res 4 ; Saved values of cursor_char..cursor_y2. + +pointer_cursor: + .byte px(%0000000),px(%0000000) + .byte px(%0100000),px(%0000000) + .byte px(%0110000),px(%0000000) + .byte px(%0111000),px(%0000000) + .byte px(%0111100),px(%0000000) + .byte px(%0111110),px(%0000000) + .byte px(%0111111),px(%0000000) + .byte px(%0101100),px(%0000000) + .byte px(%0000110),px(%0000000) + .byte px(%0000110),px(%0000000) + .byte px(%0000011),px(%0000000) + + .byte px(%0000000),px(%0000000) + .byte px(%1100000),px(%0000000) + .byte px(%1110000),px(%0000000) + .byte px(%1111000),px(%0000000) + .byte px(%1111100),px(%0000000) + .byte px(%1111110),px(%0000000) + .byte px(%1111111),px(%0000000) + .byte px(%1111111),px(%1000000) + .byte px(%1111111),px(%0000000) + .byte px(%0001111),px(%0000000) + .byte px(%0001111),px(%0000000) + .byte px(%0000111),px(%1000000) + .byte px(%0000111),px(%1000000) + + .byte 1,1 + +pointer_cursor_addr: + .addr pointer_cursor + +.proc set_pointer_cursor + lda #$FF sta cursor_count lda #0 sta cursor_flag - copy16 L6065, params_addr + lda pointer_cursor_addr + sta params_addr + lda pointer_cursor_addr+1 + sta params_addr+1 ;; fall through +.endproc ;;; ============================================================ ;;; SetCursor - cursor_height := 12 - cursor_width := 2 - cursor_mask_offset := cursor_width * cursor_height - cursor_hotspot_offset := 2 * cursor_width * cursor_height -SetCursorImpl: +.proc SetCursorImpl php sei ldax params_addr stax active_cursor clc - adc #cursor_mask_offset + adc #MGTK::cursor_offset_mask bcc :+ inx : stax active_cursor_mask - ldy #cursor_hotspot_offset + + ldy #MGTK::cursor_offset_hotspot lda (params_addr),y sta cursor_hotspot_x iny @@ -4085,199 +4114,258 @@ SetCursorImpl: jsr restore_cursor_background jsr draw_cursor plp -L60A7: rts +.endproc +srts: rts -update_cursor: + + cursor_bytes := $82 + cursor_softswitch := $83 + cursor_y1 := $84 + cursor_y2 := $85 + + vid_ptr := $88 + +.proc update_cursor lda cursor_count ; hidden? if so, skip - bne L60A7 + bne srts bit cursor_flag - bmi L60A7 + bmi srts + ;; Fall-through +.endproc -draw_cursor: - lda #$00 +.proc draw_cursor + lda #0 sta cursor_count sta cursor_flag + lda set_pos_params::ycoord clc sbc cursor_hotspot_y - sta $84 + sta cursor_y1 clc - adc #$0C - sta $85 + adc #MGTK::cursor_height + sta cursor_y2 + lda set_pos_params::xcoord sec sbc cursor_hotspot_x tax lda set_pos_params::xcoord+1 - sbc #$00 - bpl L60E1 - txa - ror a - tax - ldy mod7_table+124,x ; ??? - lda #$FF - bmi L60E4 -L60E1: jsr divmod7 -L60E4: sta $82 + sbc #0 + bpl :+ + + txa ; X-coord is negative: X-reg = X-coord + 256 + ror a ; Will shift in zero: X-reg = X-coord/2 + 128 + tax ; Negative mod7 table starts at 252 (since 252%7 = 0), and goes backwards + ldy mod7_table+252-128,x ; Index (X-coord / 2 = X-reg - 128) relative to mod7_table+252 + lda #$FF ; Char index = -1 + bmi set_divmod + +: jsr divmod7 +set_divmod: + sta cursor_bytes ; char index in line + tya rol a - cmp #$07 - bcc L60EE - sbc #$07 -L60EE: tay - lda #$2A - rol a - eor #$01 - sta $83 - sty L6004 + cmp #7 + bcc :+ + sbc #7 +: tay + + lda #= 7, then will be HISCR, else LOWSCR + eor #1 + sta cursor_softswitch ; $C0xx softswitch index + + sty cursor_mod7 tya asl a tay - copy16 shift_table_main,y, L6164 - copy16 shift_table_aux,y, L616A - ldx #$03 -L6116: lda $82,x - sta L602F,x - dex - bpl L6116 - ldx #$17 - stx $86 - ldx #$23 - ldy $85 -L6126: cpy #$C0 - bcc L612D - jmp L61B9 + copy16 shift_table_main,y, cursor_shift_main_addr + copy16 shift_table_aux,y, cursor_shift_aux_addr -L612D: lda hires_table_lo,y - sta $88 + ldx #3 +: lda cursor_bytes,x + sta cursor_data,x + dex + bpl :- + + ldx #$17 + stx left_bytes + ldx #$23 + ldy cursor_y2 +dloop: cpy #192 + bcc :+ + jmp drnext + +: lda hires_table_lo,y + sta vid_ptr lda hires_table_hi,y ora #$20 - sta $89 - sty $85 - stx $87 - ldy $86 + sta vid_ptr+1 + sty cursor_y2 + stx left_mod14 + + ldy left_bytes ldx #$01 -L6141: +: active_cursor := * + 1 lda $FFFF,y - sta L6005,x + sta cursor_bits,x active_cursor_mask := * + 1 lda $FFFF,y - sta L6008,x + sta cursor_mask,x dey dex - bpl L6141 - lda #$00 - sta L6007 - sta L600A - ldy L6004 - beq L6172 - ldy #$05 -L6160: ldx L6004,y -L6164 := * + 1 + bpl :- + lda #0 + sta cursor_bits+2 + sta cursor_mask+2 + + ldy cursor_mod7 + beq no_shift + + ldy #5 +: ldx cursor_bits-1,y + +cursor_shift_main_addr := * + 1 ora $FF80,x - sta L6005,y -L616A := * + 1 + sta cursor_bits,y + +cursor_shift_aux_addr := * + 1 lda $FF00,x dey - bne L6160 - sta L6005 -L6172: ldx $87 - ldy $82 - lda $83 - jsr L622A - bcs L618D - lda ($88),y - sta L600B,x - lda L6008 - ora ($88),y - eor L6005 - sta ($88),y + bne :- + sta cursor_bits + +no_shift: + ldx left_mod14 + ldy cursor_bytes + lda cursor_softswitch + jsr set_switch + bcs :+ + + lda (vid_ptr),y + sta cursor_savebits,x + + lda cursor_mask + ora (vid_ptr),y + eor cursor_bits + sta (vid_ptr),y dex -L618D: jsr L6220 - bcs L61A2 - lda ($88),y - sta L600B,x - lda L6009 - ora ($88),y - eor L6006 - sta ($88),y +: + jsr switch_page + bcs :+ + + lda (vid_ptr),y + sta cursor_savebits,x + lda cursor_mask+1 + + ora (vid_ptr),y + eor cursor_bits+1 + sta (vid_ptr),y dex -L61A2: jsr L6220 - bcs L61B7 - lda ($88),y - sta L600B,x - lda L600A - ora ($88),y - eor L6007 - sta ($88),y +: + jsr switch_page + bcs :+ + + lda (vid_ptr),y + sta cursor_savebits,x + + lda cursor_mask+2 + ora (vid_ptr),y + eor cursor_bits+2 + sta (vid_ptr),y dex -L61B7: ldy $85 -L61B9: dec $86 - dec $86 +: + ldy cursor_y2 +drnext: + dec left_bytes + dec left_bytes dey - cpy $84 - beq L621C - jmp L6126 + cpy cursor_y1 + beq lowscr_rts + jmp dloop +.endproc +drts: rts -L61C5: rts +active_cursor := draw_cursor::active_cursor +active_cursor_mask := draw_cursor::active_cursor_mask -restore_cursor_background: + +.proc restore_cursor_background lda cursor_count ; already hidden? - bne L61C5 + bne drts bit cursor_flag - bmi L61C5 + bmi drts - ldx #$03 -L61D2: lda L602F,x - sta $82,x + ldx #3 +: lda cursor_data,x + sta cursor_bytes,x dex - bpl L61D2 + bpl :- + ldx #$23 - ldy $85 -L61DE: cpy #$C0 - bcs L6217 + ldy cursor_y2 +cloop: cpy #192 + bcs cnext + lda hires_table_lo,y - sta $88 + sta vid_ptr lda hires_table_hi,y ora #$20 - sta $89 - sty $85 - ldy $82 - lda $83 - jsr L622A - bcs L61FF - lda L600B,x - sta ($88),y + sta vid_ptr+1 + sty cursor_y2 + + ldy cursor_bytes + lda cursor_softswitch + jsr set_switch + bcs :+ + lda cursor_savebits,x + sta (vid_ptr),y dex -L61FF: jsr L6220 - bcs L620A - lda L600B,x - sta ($88),y +: + jsr switch_page + bcs :+ + lda cursor_savebits,x + sta (vid_ptr),y dex -L620A: jsr L6220 - bcs L6215 - lda L600B,x - sta ($88),y +: + jsr switch_page + bcs :+ + lda cursor_savebits,x + sta (vid_ptr),y dex -L6215: ldy $85 -L6217: dey - cpy $84 - bne L61DE -L621C: sta LOWSCR +: + ldy cursor_y2 +cnext: dey + cpy cursor_y1 + bne cloop +.endproc +lowscr_rts: + sta LOWSCR rts -L6220: lda L622E - eor #$01 - cmp #$54 - beq L622A - iny -L622A: sta L622E - L622E := *+1 +.proc switch_page + lda set_switch_sta_addr + eor #1 + cmp #