a2d/desk.acc/date.s

955 lines
20 KiB
ArmAsm
Raw Normal View History

2017-09-11 03:40:32 +00:00
.org $800
.setcpu "65C02"
2017-09-11 03:40:32 +00:00
.include "apple2.inc"
2017-09-15 04:13:54 +00:00
.include "../inc/apple2.inc"
2017-09-11 03:40:32 +00:00
.include "../inc/prodos.inc"
.include "../inc/auxmem.inc"
2017-09-11 03:40:32 +00:00
.include "a2d.inc"
2017-09-13 07:04:21 +00:00
;;; ==================================================
jmp copy2aux
2017-09-14 02:31:54 +00:00
2017-09-13 05:01:45 +00:00
stash_stack: .byte $00
2017-09-14 02:31:54 +00:00
;;; ==================================================
;;; MLI Call Param Blocks
filename:
PASCAL_STRING "MD.SYSTEM"
.proc open_params
params: .byte 3
name: .addr filename
buffer: .addr $0900
ref_num:.byte 0
.endproc
.proc set_mark_params
params: .byte 2
ref_num:.byte 0
pos: .byte $03,$00,$00
.endproc
.proc write_params
params: .byte 4
ref_num:.byte 0
buffer: .addr write_buffer
request:.word sizeof_write_buffer
trans: .word 0
.endproc
.proc close_params
params: .byte 1
ref_num:.byte 0
.endproc
write_buffer:
.byte 0,0
sizeof_write_buffer := * - write_buffer
2017-09-11 03:40:32 +00:00
2017-09-13 07:04:21 +00:00
;;; ==================================================
.proc copy2aux
start := start_da
end := last
tsx
2017-09-13 05:01:45 +00:00
stx stash_stack
sta ALTZPOFF
lda ROMIN2
lda DATELO
2017-09-13 05:01:45 +00:00
sta datelo
lda DATEHI
2017-09-13 05:01:45 +00:00
sta datehi
lda #<start
2017-09-11 03:40:32 +00:00
sta STARTLO
lda #>start
2017-09-11 03:40:32 +00:00
sta STARTHI
lda #<end
2017-09-11 03:40:32 +00:00
sta ENDLO
lda #>end
2017-09-11 03:40:32 +00:00
sta ENDHI
lda #<start
2017-09-11 03:40:32 +00:00
sta DESTINATIONLO
lda #>start
2017-09-11 03:40:32 +00:00
sta DESTINATIONHI
sec
jsr AUXMOVE
lda #<start
sta XFERSTARTLO
lda #>start
sta XFERSTARTHI
php
pla
ora #$40 ; set overflow: aux zp/stack
pha
plp
sec ; control main>aux
jmp XFER
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-14 02:31:54 +00:00
;;; Write date into MD.SYSTEM file and exit the DA
2017-09-13 07:04:21 +00:00
2017-09-14 02:31:54 +00:00
.proc save_date_and_exit
sta ALTZPON
sta write_buffer
stx write_buffer+1
lda LCBANK1
lda LCBANK1
2017-09-14 02:31:54 +00:00
lda write_buffer ; Dialog committed?
beq skip
ldy #OPEN ; open the file
lda #<open_params
ldx #>open_params
jsr JUMP_TABLE_MLI
bne skip
lda open_params::ref_num
sta set_mark_params::ref_num
sta write_params::ref_num
sta close_params::ref_num
ldy #SET_MARK ; seek
lda #<set_mark_params
ldx #>set_mark_params
jsr JUMP_TABLE_MLI
bne close
ldy #WRITE ; write the date
lda #<write_params
ldx #>write_params
jsr JUMP_TABLE_MLI
close: ldy #CLOSE ; close the file
lda #<close_params
ldx #>close_params
jsr JUMP_TABLE_MLI
skip: ldx stash_stack ; exit the DA
txs
rts
2017-09-14 02:31:54 +00:00
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
start_da:
sta ALTZPON
lda LCBANK1
lda LCBANK1
2017-09-13 08:28:28 +00:00
jmp init_window
2017-09-13 07:04:21 +00:00
;;; ==================================================
;;; Param blocks
2017-09-13 08:28:28 +00:00
;; The following 7 rects are iterated over to identify
;; a hit target for a click.
num_hit_rects := 7
first_hit_rect := *
up_rect_index := 3
down_rect_index := 4
2017-09-13 04:27:27 +00:00
ok_button_rect:
2017-09-13 05:01:45 +00:00
.word $6A,$2E,$B5,$39
2017-09-13 04:27:27 +00:00
cancel_button_rect:
2017-09-13 05:01:45 +00:00
.word $10,$2E,$5A,$39
2017-09-13 04:27:27 +00:00
up_arrow_rect:
.word $AA,$0A,$B4,$14
down_arrow_rect:
2017-09-13 05:01:45 +00:00
.word $AA,$1E,$B4,$28
2017-09-13 08:28:28 +00:00
day_rect:
2017-09-13 05:01:45 +00:00
.word $25,$14,$3B,$1E
2017-09-13 08:28:28 +00:00
month_rect:
2017-09-13 05:01:45 +00:00
.word $51,$14,$6F,$1E
2017-09-13 08:28:28 +00:00
year_rect:
2017-09-13 05:01:45 +00:00
.word $7F,$14,$95,$1E
2017-09-13 04:27:27 +00:00
2017-09-19 05:51:24 +00:00
.proc text_mask_params
mask: .byte 0
.endproc
.res 7, $00 ; ???
.byte $FF
.proc white_pattern
.res 8, $FF
.endproc
2017-09-13 15:09:33 +00:00
.byte $FF ; ??
2017-09-13 05:01:45 +00:00
2017-09-13 15:09:33 +00:00
selected_field: ; 1 = day, 2 = month, 3 = year, 0 = none (init)
2017-09-13 05:01:45 +00:00
.byte 0
2017-09-13 08:28:28 +00:00
datelo: .byte 0
datehi: .byte 0
2017-09-13 05:01:45 +00:00
day: .byte 26 ; Feb 26, 1985
month: .byte 2 ; The date this was written?
year: .byte 85
spaces_string:
A2D_DEFSTRING " "
day_pos:
.word 43, 30
2017-09-13 05:01:45 +00:00
day_string:
A2D_DEFSTRING " "
month_pos:
.word 87, 30
2017-09-13 05:01:45 +00:00
month_string:
A2D_DEFSTRING " "
year_pos:
.word 133, 30
2017-09-13 05:01:45 +00:00
year_string:
A2D_DEFSTRING " "
.proc get_input_params
2017-09-13 08:28:28 +00:00
state: .byte 0
key := *
modifiers := *+1
xcoord := *
ycoord := *+2
.byte 0,0,0,0
.endproc
;; xcoord/ycoord are used to query...
.proc query_target_params
xcoord := *
ycoord := *+2
element:.byte 0
id: .byte 0
.endproc
window_id := 100
2017-09-13 08:28:28 +00:00
.proc map_coords_params
id: .byte window_id
screen:
screenx:.word 0
screeny:.word 0
client:
clientx:.word 0
clienty:.word 0
.endproc
2017-09-13 15:09:33 +00:00
.proc destroy_window_params
id: .byte window_id
.endproc
.byte $00,$01 ; ???
.proc fill_mode_params
2017-09-13 15:09:33 +00:00
mode: .byte $02 ; this should be normal, but we do inverts ???
.endproc
2017-09-13 15:09:33 +00:00
.byte $06 ; ???
.proc create_window_params
2017-09-13 08:28:28 +00:00
id: .byte window_id
flags: .byte A2D_CWF_NOTITLE
title: .addr 0
hscroll:.byte A2D_CWS_NOSCROLL
vscroll:.byte A2D_CWS_NOSCROLL
hsmax: .byte 0
hspos: .byte 0
vsmax: .byte 0
vspos: .byte 0
.byte 0, 0 ; ???
w1: .word 100
h1: .word 100
w2: .word $1F4
h2: .word $1F4
.proc box
2017-09-15 08:02:38 +00:00
left: .word 180
top: .word 50
saddr: .addr A2D_SCREEN_ADDR
stride: .word A2D_SCREEN_STRIDE
hoffset:.word 0
voffset:.word 0
width: .word $C7
height: .word $40
.endproc
pattern:.res 8,$00
2017-09-15 08:02:38 +00:00
mskand: .byte A2D_DEFAULT_MSKAND
mskor: .byte A2D_DEFAULT_MSKOR
.byte 0,0,0,0 ; ???
hthick: .byte 4
vthick: .byte 2
.byte 0 ; ???
tmask: .byte $7F
font: .addr A2D_DEFAULT_FONT
next: .addr 0
.endproc
2017-09-11 03:40:32 +00:00
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 15:09:33 +00:00
;;; Initialize window, unpack the date.
2017-09-13 07:04:21 +00:00
2017-09-13 08:28:28 +00:00
init_window:
jsr save_zp
;; Crack the date bytes. Format is:
;; | DATEHI | DATELO |
;; |7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0|
;; | year | month | day |
2017-09-13 05:01:45 +00:00
lda datehi
lsr a
2017-09-13 05:01:45 +00:00
sta year
2017-09-13 08:28:28 +00:00
2017-09-13 05:01:45 +00:00
lda datelo
2017-09-13 08:28:28 +00:00
and #%11111
2017-09-13 05:01:45 +00:00
sta day
2017-09-13 08:28:28 +00:00
2017-09-13 05:01:45 +00:00
lda datehi
ror a
2017-09-13 05:01:45 +00:00
lda datelo
ror a
lsr a
lsr a
lsr a
lsr a
2017-09-13 05:01:45 +00:00
sta month
2017-09-13 08:28:28 +00:00
A2D_CALL A2D_CREATE_WINDOW, create_window_params
2017-09-13 05:01:45 +00:00
lda #0
sta selected_field
jsr draw_window
2017-09-11 03:40:32 +00:00
A2D_CALL $2B
2017-09-13 15:09:33 +00:00
;; fall through
2017-09-13 07:04:21 +00:00
;;; ==================================================
;;; Input loop
2017-09-13 15:09:33 +00:00
.proc input_loop
2017-09-13 07:04:21 +00:00
A2D_CALL A2D_GET_INPUT, get_input_params
2017-09-13 08:28:28 +00:00
lda get_input_params::state
2017-09-13 07:04:21 +00:00
cmp #A2D_INPUT_DOWN
bne :+
jsr on_click
2017-09-13 07:04:21 +00:00
jmp input_loop
: cmp #A2D_INPUT_KEY
bne input_loop
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc on_key
2017-09-13 08:28:28 +00:00
lda get_input_params::modifiers
2017-09-13 07:04:21 +00:00
bne input_loop
2017-09-13 08:28:28 +00:00
lda get_input_params::key
2017-09-16 21:20:41 +00:00
cmp #KEY_RETURN
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 08:28:28 +00:00
jmp on_ok
2017-09-13 07:04:21 +00:00
: cmp #KEY_ESCAPE
bne :+
jmp on_cancel
: cmp #KEY_LEFT
beq on_key_left
cmp #KEY_RIGHT
beq on_key_right
cmp #KEY_DOWN
beq on_key_down
cmp #KEY_UP
bne input_loop
on_key_up:
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_FILL_RECT, up_arrow_rect
2017-09-13 08:28:28 +00:00
lda #up_rect_index
sta hit_rect_index
jsr do_inc_or_dec
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_FILL_RECT, up_arrow_rect
2017-09-13 07:04:21 +00:00
jmp input_loop
2017-09-13 07:04:21 +00:00
on_key_down:
A2D_CALL A2D_FILL_RECT, down_arrow_rect
2017-09-13 08:28:28 +00:00
lda #down_rect_index
sta hit_rect_index
jsr do_inc_or_dec
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_FILL_RECT, down_arrow_rect
2017-09-13 07:04:21 +00:00
jmp input_loop
2017-09-13 07:04:21 +00:00
on_key_left:
sec
2017-09-13 05:01:45 +00:00
lda selected_field
sbc #1
2017-09-13 15:09:33 +00:00
bne update_selection
2017-09-13 05:01:45 +00:00
lda #3
2017-09-13 15:09:33 +00:00
jmp update_selection
2017-09-13 07:04:21 +00:00
on_key_right:
clc
2017-09-13 05:01:45 +00:00
lda selected_field
adc #1
cmp #4
2017-09-13 15:09:33 +00:00
bne update_selection
2017-09-13 05:01:45 +00:00
lda #1
2017-09-13 15:09:33 +00:00
update_selection:
jsr highlight_selected_field
2017-09-13 07:04:21 +00:00
jmp input_loop
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
.proc on_click
2017-09-13 08:28:28 +00:00
A2D_CALL A2D_QUERY_TARGET, get_input_params::xcoord
A2D_CALL A2D_SET_FILL_MODE, fill_mode_params
A2D_CALL A2D_SET_PATTERN, white_pattern
2017-09-13 08:28:28 +00:00
lda query_target_params::id
cmp #window_id
bne miss
lda query_target_params::element
bne hit
2017-09-13 08:28:28 +00:00
miss: rts
hit: cmp #A2D_ELEM_CLIENT
2017-09-13 08:28:28 +00:00
bne miss
jsr find_hit_target
cpx #0
beq miss
txa
sec
2017-09-13 08:28:28 +00:00
sbc #1
asl a
tay
2017-09-13 08:28:28 +00:00
lda hit_target_jump_table,y
sta jump+1
lda hit_target_jump_table+1,y
sta jump+2
2017-09-13 15:09:33 +00:00
jump: jmp $1000 ; self modified
2017-09-13 08:28:28 +00:00
hit_target_jump_table:
.addr on_ok, on_cancel, on_up, on_down
.addr on_field_click, on_field_click, on_field_click
.endproc
;;; ==================================================
.proc on_ok
2017-09-13 07:04:21 +00:00
A2D_CALL A2D_FILL_RECT, ok_button_rect
2017-09-13 08:28:28 +00:00
;; Pack the date bytes and store
sta RAMWRTOFF
2017-09-13 05:01:45 +00:00
lda month
asl a
asl a
asl a
asl a
asl a
2017-09-13 05:01:45 +00:00
ora day
sta DATELO
2017-09-13 05:01:45 +00:00
lda year
rol a
sta DATEHI
sta RAMWRTON
2017-09-13 08:28:28 +00:00
lda #1
sta dialog_result
jmp destroy
.endproc
2017-09-13 07:04:21 +00:00
on_cancel:
A2D_CALL A2D_FILL_RECT, cancel_button_rect
2017-09-13 08:28:28 +00:00
lda #0
sta dialog_result
jmp destroy
2017-09-13 07:04:21 +00:00
on_up:
txa
pha
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_FILL_RECT, up_arrow_rect
pla
tax
2017-09-13 08:28:28 +00:00
jsr on_up_or_down
rts
2017-09-13 07:04:21 +00:00
on_down:
txa
pha
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_FILL_RECT, down_arrow_rect
pla
tax
2017-09-13 08:28:28 +00:00
jsr on_up_or_down
rts
2017-09-13 08:28:28 +00:00
on_field_click:
txa
sec
2017-09-13 08:28:28 +00:00
sbc #4
2017-09-13 15:09:33 +00:00
jmp highlight_selected_field
2017-09-13 08:28:28 +00:00
.proc on_up_or_down
stx hit_rect_index
loop: A2D_CALL A2D_GET_INPUT, get_input_params ; Repeat while mouse is down
lda get_input_params::state
cmp #A2D_INPUT_UP
beq :+
jsr do_inc_or_dec
jmp loop
: lda hit_rect_index
cmp #up_rect_index
beq :+
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_FILL_RECT, down_arrow_rect
rts
2017-09-13 08:28:28 +00:00
: A2D_CALL A2D_FILL_RECT, up_arrow_rect
rts
2017-09-13 08:28:28 +00:00
.endproc
2017-09-13 08:28:28 +00:00
.proc do_inc_or_dec
ptr := $7
2017-09-13 15:09:33 +00:00
jsr delay
2017-09-13 08:28:28 +00:00
lda hit_rect_index
cmp #up_rect_index
beq incr
decr: lda #<decrement_table
sta ptr
lda #>decrement_table
sta ptr+1
jmp go
incr: lda #<increment_table
sta ptr
lda #>increment_table
sta ptr+1
go: lda selected_field
asl a
tay
2017-09-13 08:28:28 +00:00
lda (ptr),y
sta gosub+1
iny
2017-09-13 08:28:28 +00:00
lda (ptr),y
sta gosub+2
2017-09-13 15:09:33 +00:00
gosub: jsr $1000 ; self modified
2017-09-19 05:51:24 +00:00
A2D_CALL A2D_SET_TEXT_MASK, text_mask_params
2017-09-13 08:28:28 +00:00
jmp draw_selected_field
.endproc
hit_rect_index:
.byte 0
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 08:28:28 +00:00
increment_table:
.addr 0, increment_day, increment_month, increment_year
decrement_table:
.addr 0, decrement_day, decrement_month, decrement_year
2017-09-13 07:04:21 +00:00
2017-09-13 15:09:33 +00:00
day_min := 1
day_max := 31
month_min := 1
month_max := 12
year_min := 0
year_max := 99
2017-09-13 07:04:21 +00:00
increment_day:
clc
2017-09-13 05:01:45 +00:00
lda day
2017-09-13 07:04:21 +00:00
adc #1
2017-09-13 15:09:33 +00:00
cmp #day_max+1
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 15:09:33 +00:00
lda #month_min
2017-09-13 07:04:21 +00:00
: sta day
2017-09-13 05:01:45 +00:00
jmp prepare_day_string
2017-09-13 07:04:21 +00:00
increment_month:
clc
2017-09-13 05:01:45 +00:00
lda month
2017-09-13 07:04:21 +00:00
adc #1
2017-09-13 15:09:33 +00:00
cmp #month_max+1
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 15:09:33 +00:00
lda #month_min
2017-09-13 07:04:21 +00:00
: sta month
2017-09-13 05:01:45 +00:00
jmp prepare_month_string
2017-09-13 07:04:21 +00:00
increment_year:
clc
2017-09-13 05:01:45 +00:00
lda year
2017-09-13 07:04:21 +00:00
adc #1
2017-09-13 15:09:33 +00:00
cmp #year_max+1
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 15:09:33 +00:00
lda #year_min
2017-09-13 07:04:21 +00:00
: sta year
2017-09-13 05:01:45 +00:00
jmp prepare_year_string
2017-09-13 07:04:21 +00:00
decrement_day:
2017-09-13 05:01:45 +00:00
dec day
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 15:09:33 +00:00
lda #day_max
2017-09-13 05:01:45 +00:00
sta day
2017-09-13 07:04:21 +00:00
: jmp prepare_day_string
2017-09-13 07:04:21 +00:00
decrement_month:
2017-09-13 05:01:45 +00:00
dec month
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 15:09:33 +00:00
lda #month_max
2017-09-13 05:01:45 +00:00
sta month
2017-09-13 07:04:21 +00:00
: jmp prepare_month_string
2017-09-13 07:04:21 +00:00
decrement_year:
2017-09-13 05:01:45 +00:00
dec year
2017-09-13 07:04:21 +00:00
bpl :+
2017-09-13 15:09:33 +00:00
lda #year_max
2017-09-13 05:01:45 +00:00
sta year
2017-09-13 07:04:21 +00:00
: jmp prepare_year_string
;;; ==================================================
2017-09-13 05:01:45 +00:00
.proc prepare_day_string
lda day
2017-09-13 08:28:28 +00:00
jsr number_to_ascii
2017-09-13 05:01:45 +00:00
sta day_string+3 ; first char
stx day_string+4 ; second char
rts
2017-09-13 05:01:45 +00:00
.endproc
2017-09-13 05:01:45 +00:00
.proc prepare_month_string
lda month ; month * 3 - 1
asl a
clc
2017-09-13 05:01:45 +00:00
adc month
tax
dex
2017-09-13 05:01:45 +00:00
ptr := $07
str := month_string + 3
2017-09-13 08:28:28 +00:00
len := 3
2017-09-13 05:01:45 +00:00
lda #<str
sta ptr
lda #>str
sta ptr+1
2017-09-13 08:28:28 +00:00
ldy #len - 1
2017-09-13 05:01:45 +00:00
loop: lda month_name_table,x
sta (ptr),y
dex
dey
2017-09-13 05:01:45 +00:00
bpl loop
rts
2017-09-13 05:01:45 +00:00
.endproc
2017-09-13 05:01:45 +00:00
month_name_table:
.byte "Jan","Feb","Mar","Apr","May","Jun"
.byte "Jul","Aug","Sep","Oct","Nov","Dec"
2017-09-13 15:09:33 +00:00
.proc prepare_year_string
2017-09-13 05:01:45 +00:00
lda year
2017-09-13 08:28:28 +00:00
jsr number_to_ascii
2017-09-13 05:01:45 +00:00
sta year_string+3
stx year_string+4
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 15:09:33 +00:00
;;; Tear down the window and exit
2017-09-13 07:04:21 +00:00
2017-09-13 08:28:28 +00:00
dialog_result: .byte 0
.proc destroy
2017-09-13 15:09:33 +00:00
A2D_CALL A2D_DESTROY_WINDOW, destroy_window_params
DESKTOP_CALL DESKTOP_REDRAW_ICONS
2017-09-13 08:28:28 +00:00
;; Copy the relay routine to the zero page
dest := $20
ldx #sizeof_routine
loop: lda routine,x
sta dest,x
dex
2017-09-13 08:28:28 +00:00
bpl loop
lda dialog_result
beq skip
;; Pack date bytes, store in X, A
2017-09-13 05:01:45 +00:00
lda month
asl a
asl a
asl a
asl a
asl a
2017-09-13 05:01:45 +00:00
ora day
tay
2017-09-13 05:01:45 +00:00
lda year
rol a
tax
tya
2017-09-13 08:28:28 +00:00
skip: jmp dest
.proc routine
sta RAMRDOFF
sta RAMWRTOFF
2017-09-14 02:31:54 +00:00
jmp save_date_and_exit
2017-09-13 08:28:28 +00:00
.endproc
sizeof_routine := * - routine
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 15:09:33 +00:00
;;; Figure out which button was hit (if any).
;;; Index returned in X.
2017-09-13 07:04:21 +00:00
2017-09-13 08:28:28 +00:00
.proc find_hit_target
lda get_input_params::xcoord
sta map_coords_params::screenx
lda get_input_params::xcoord+1
sta map_coords_params::screenx+1
lda get_input_params::ycoord
sta map_coords_params::screeny
lda get_input_params::ycoord+1
sta map_coords_params::screeny+1
A2D_CALL A2D_MAP_COORDS, map_coords_params
A2D_CALL A2D_SET_POS, map_coords_params::client
ldx #1
lda #<first_hit_rect
sta test_addr
lda #>first_hit_rect
sta test_addr+1
loop: txa
pha
2017-09-13 08:28:28 +00:00
A2D_CALL A2D_TEST_BOX, $1000, test_addr
bne done
clc
2017-09-13 08:28:28 +00:00
lda test_addr
2017-09-13 15:09:33 +00:00
adc #8 ; size of 4 words
2017-09-13 08:28:28 +00:00
sta test_addr
bcc :+
inc test_addr+1
: pla
tax
inx
2017-09-13 08:28:28 +00:00
cpx #num_hit_rects+1
bne loop
ldx #0
rts
2017-09-13 08:28:28 +00:00
done: pla
tax
rts
2017-09-13 08:28:28 +00:00
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
;;; Params for the display
2017-09-13 15:09:33 +00:00
border_rect:
.word $04,$02,$C0,$3D
date_rect:
.word $20,$0F,$9A,$23
2017-09-13 04:27:27 +00:00
label_ok:
A2D_DEFSTRING {"OK ",A2D_GLYPH_RETURN} ;
2017-09-13 04:27:27 +00:00
label_cancel:
A2D_DEFSTRING "Cancel ESC"
label_uparrow:
A2D_DEFSTRING A2D_GLYPH_UARROW
2017-09-13 04:27:27 +00:00
label_downarrow:
A2D_DEFSTRING A2D_GLYPH_DARROW
2017-09-13 04:27:27 +00:00
label_cancel_pos:
.word $15,$38
label_ok_pos:
.word $6E,$38
label_uparrow_pos:
.word $AC,$13
label_downarrow_pos:
.word $AC,$27
.proc thickness_params
hthick: .byte 1
vthick: .byte 1
.endproc
2017-09-13 04:27:27 +00:00
2017-09-13 07:04:21 +00:00
;;; ==================================================
;;; Render the window contents
draw_window:
2017-09-14 04:35:23 +00:00
A2D_CALL A2D_SET_STATE, create_window_params::box
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_DRAW_RECT, border_rect
A2D_CALL A2D_SET_THICKNESS, thickness_params
2017-09-13 04:27:27 +00:00
A2D_CALL A2D_DRAW_RECT, date_rect
A2D_CALL A2D_DRAW_RECT, ok_button_rect
A2D_CALL A2D_DRAW_RECT, cancel_button_rect
A2D_CALL A2D_SET_POS, label_ok_pos
A2D_CALL A2D_DRAW_TEXT, label_ok
A2D_CALL A2D_SET_POS, label_cancel_pos
A2D_CALL A2D_DRAW_TEXT, label_cancel
A2D_CALL A2D_SET_POS, label_uparrow_pos
A2D_CALL A2D_DRAW_TEXT, label_uparrow
A2D_CALL A2D_DRAW_RECT, up_arrow_rect
A2D_CALL A2D_SET_POS, label_downarrow_pos
A2D_CALL A2D_DRAW_TEXT, label_downarrow
A2D_CALL A2D_DRAW_RECT, down_arrow_rect
2017-09-13 05:01:45 +00:00
jsr prepare_day_string
jsr prepare_month_string
jsr prepare_year_string
jsr draw_day
jsr draw_month
jsr draw_year
A2D_CALL A2D_SET_FILL_MODE, fill_mode_params
A2D_CALL A2D_SET_PATTERN, white_pattern
2017-09-13 05:01:45 +00:00
lda #1
2017-09-13 15:09:33 +00:00
jmp highlight_selected_field
2017-09-13 15:09:33 +00:00
.proc draw_selected_field
2017-09-13 08:28:28 +00:00
lda selected_field
2017-09-13 05:01:45 +00:00
cmp #1
beq draw_day
cmp #2
beq draw_month
jmp draw_year
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc draw_day
2017-09-13 05:01:45 +00:00
A2D_CALL A2D_SET_POS, day_pos
A2D_CALL A2D_DRAW_TEXT, day_string
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc draw_month
2017-09-13 05:01:45 +00:00
A2D_CALL A2D_SET_POS, month_pos
A2D_CALL A2D_DRAW_TEXT, spaces_string ; variable width, so clear first
A2D_CALL A2D_SET_POS, month_pos
A2D_CALL A2D_DRAW_TEXT, month_string
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc draw_year
2017-09-13 05:01:45 +00:00
A2D_CALL A2D_SET_POS, year_pos
A2D_CALL A2D_DRAW_TEXT, year_string
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 15:09:33 +00:00
;;; Highlight selected field
;;; Previously selected field in A, newly selected field at top of stack.
2017-09-13 07:04:21 +00:00
2017-09-13 15:09:33 +00:00
.proc highlight_selected_field
pha
lda selected_field ; initial state is 0, so nothing
beq update ; to invert back to normal
cmp #1 ; day?
bne :+
jsr fill_day
jmp update
: cmp #2 ; month?
bne :+
jsr fill_month
jmp update
2017-09-13 15:09:33 +00:00
: jsr fill_year ; year!
2017-09-13 15:09:33 +00:00
update: pla ; update selection
2017-09-13 05:01:45 +00:00
sta selected_field
cmp #1
2017-09-13 15:09:33 +00:00
beq fill_day
2017-09-13 05:01:45 +00:00
cmp #2
2017-09-13 15:09:33 +00:00
beq fill_month
fill_year:
A2D_CALL A2D_FILL_RECT, year_rect
rts
2017-09-13 15:09:33 +00:00
fill_day:
A2D_CALL A2D_FILL_RECT, day_rect
rts
2017-09-13 15:09:33 +00:00
fill_month:
A2D_CALL A2D_FILL_RECT, month_rect
rts
2017-09-13 15:09:33 +00:00
.endproc
;;; ==================================================
;;; Delay
2017-09-13 15:09:33 +00:00
.proc delay
lda #255
sec
2017-09-13 15:09:33 +00:00
loop1: pha
loop2: sbc #1
bne loop2
pla
2017-09-13 15:09:33 +00:00
sbc #1
bne loop1
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 08:28:28 +00:00
;;; Save/restore Zero Page
2017-09-13 07:04:21 +00:00
2017-09-13 08:28:28 +00:00
.proc save_zp
ldx #$00
loop: lda $00,x
2017-09-13 07:04:21 +00:00
sta zp_buffer,x
dex
2017-09-13 08:28:28 +00:00
bne loop
rts
2017-09-13 08:28:28 +00:00
.endproc
2017-09-13 08:28:28 +00:00
.proc restore_zp
ldx #$00
2017-09-13 08:28:28 +00:00
loop: lda zp_buffer,x
sta $00,x
dex
2017-09-13 08:28:28 +00:00
bne loop
rts
2017-09-13 08:28:28 +00:00
.endproc
2017-09-13 07:04:21 +00:00
zp_buffer:
.res 256, 0
2017-09-13 07:04:21 +00:00
;;; ==================================================
2017-09-13 08:28:28 +00:00
;;; Convert number to two ASCII digits (in A, X)
2017-09-11 03:40:32 +00:00
2017-09-13 08:28:28 +00:00
.proc number_to_ascii
2017-09-13 05:03:23 +00:00
ldy #0
2017-09-13 08:28:28 +00:00
loop: cmp #10
bcc :+
sec
2017-09-13 05:03:23 +00:00
sbc #10
iny
jmp loop
2017-09-13 08:28:28 +00:00
: clc
2017-09-13 04:27:27 +00:00
adc #'0'
tax
tya
clc
2017-09-13 04:27:27 +00:00
adc #'0'
2017-09-13 08:28:28 +00:00
rts
.endproc
rts ; ???
last := *