a2d/desk.acc/date.s

896 lines
20 KiB
ArmAsm
Raw Normal View History

.setcpu "6502"
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"
2018-01-29 05:18:00 +00:00
.include "../mgtk.inc"
.include "../desktop.inc" ; redraw icons after window move; font; glyphs
2018-02-07 02:42:00 +00:00
.include "../macros.inc"
.org $800
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-14 02:31:54 +00:00
;;; MLI Call Param Blocks
filename:
PASCAL_STRING "MD.SYSTEM"
2018-02-27 04:51:23 +00:00
DEFINE_OPEN_PARAMS open_params, filename, $900
DEFINE_SET_MARK_PARAMS set_mark_params, 3
DEFINE_WRITE_PARAMS write_params, write_buffer, sizeof_write_buffer
DEFINE_CLOSE_PARAMS close_params
2017-09-14 02:31:54 +00:00
write_buffer:
.byte 0,0
sizeof_write_buffer := * - write_buffer
2017-09-11 03:40:32 +00:00
2018-03-05 05:36:00 +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
2018-02-07 02:42:00 +00:00
copy16 #start, STARTLO
copy16 #end, ENDLO
copy16 #start, DESTINATIONLO
sec
jsr AUXMOVE
2018-02-07 02:42:00 +00:00
copy16 #start, XFERSTARTLO
php
pla
ora #$40 ; set overflow: aux zp/stack
pha
plp
sec ; control main>aux
jmp XFER
.endproc
2018-03-05 05:36:00 +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
2018-02-07 02:42:00 +00:00
2017-09-14 02:31:54 +00:00
ldy #OPEN ; open the file
2018-02-07 02:42:00 +00:00
ldax #open_params
2017-09-14 02:31:54 +00:00
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
2018-02-07 02:42:00 +00:00
ldax #set_mark_params
2017-09-14 02:31:54 +00:00
jsr JUMP_TABLE_MLI
bne close
ldy #WRITE ; write the date
2018-02-07 02:42:00 +00:00
ldax #write_params
2017-09-14 02:31:54 +00:00
jsr JUMP_TABLE_MLI
close: ldy #CLOSE ; close the file
2018-02-07 02:42:00 +00:00
ldax #close_params
2017-09-14 02:31:54 +00:00
jsr JUMP_TABLE_MLI
skip: ldx stash_stack ; exit the DA
txs
rts
2017-09-14 02:31:54 +00:00
.endproc
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-01-30 04:14:34 +00:00
.proc settextbg_params
2018-01-30 04:49:42 +00:00
backcolor: .byte 0 ; black
2017-09-19 05:51:24 +00:00
.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:
2018-01-29 05:18:00 +00:00
DEFINE_STRING " "
2017-09-13 05:01:45 +00:00
day_pos:
.word 43, 30
2017-09-13 05:01:45 +00:00
day_string:
2018-01-29 05:18:00 +00:00
DEFINE_STRING " "
2017-09-13 05:01:45 +00:00
month_pos:
.word 87, 30
2017-09-13 05:01:45 +00:00
month_string:
2018-01-29 05:18:00 +00:00
DEFINE_STRING " "
2017-09-13 05:01:45 +00:00
year_pos:
.word 133, 30
2017-09-13 05:01:45 +00:00
year_string:
2018-01-29 05:18:00 +00:00
DEFINE_STRING " "
2018-01-30 04:14:34 +00:00
.proc event_params
2018-01-30 05:11:32 +00:00
kind: .byte 0
2017-09-13 08:28:28 +00:00
key := *
modifiers := *+1
xcoord := *
ycoord := *+2
.byte 0,0,0,0
.endproc
;; xcoord/ycoord are used to query...
2018-01-30 04:14:34 +00:00
.proc findwindow_params
2018-01-30 04:49:42 +00:00
mousex := *
mousey := *+2
which_area:.byte 0
window_id: .byte 0
.endproc
2018-01-31 08:05:54 +00:00
da_window_id := 100
2017-09-13 08:28:28 +00:00
2018-01-30 04:14:34 +00:00
.proc screentowindow_params
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id
2017-09-13 08:28:28 +00:00
screen:
screenx:.word 0
screeny:.word 0
2018-01-30 04:49:42 +00:00
window:
windowx:.word 0
windowy:.word 0
2017-09-13 08:28:28 +00:00
.endproc
2018-01-30 04:14:34 +00:00
.proc closewindow_params
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id
2017-09-13 15:09:33 +00:00
.endproc
.byte $00,$01 ; ???
2018-01-30 04:14:34 +00:00
.proc penmode_params
2018-01-30 05:11:32 +00:00
penmode: .byte $02 ; this should be normal, but we do inverts ???
.endproc
2017-09-13 15:09:33 +00:00
.byte $06 ; ???
2018-01-30 04:49:42 +00:00
.proc winfo
2018-01-31 08:05:54 +00:00
window_id: .byte da_window_id
2018-01-30 04:49:42 +00:00
options:.byte MGTK::option_dialog_box
title: .addr 0
2018-01-29 05:18:00 +00:00
hscroll:.byte MGTK::scroll_option_none
vscroll:.byte MGTK::scroll_option_none
2018-01-30 04:49:42 +00:00
hthumbmax: .byte 0
hthumbpos: .byte 0
vthumbmax: .byte 0
vthumbpos: .byte 0
status: .byte 0
reserved: .byte 0
mincontwidth: .word 100
2018-01-31 08:05:54 +00:00
maxcontwidth: .word 100
mincontlength: .word $1F4
2018-01-30 04:49:42 +00:00
maxcontlength: .word $1F4
2018-01-31 08:05:54 +00:00
port:
viewloc: DEFINE_POINT 180, 50
2018-01-30 04:49:42 +00:00
mapbits: .addr MGTK::screen_mapbits
mapwidth: .word MGTK::screen_mapwidth
2018-01-31 08:05:54 +00:00
cliprect: DEFINE_RECT 0, 0, $C7, $40
pattern:.res 8,$00
2018-01-30 05:11:32 +00:00
colormasks: .byte MGTK::colormask_and, MGTK::colormask_or
2018-01-31 08:05:54 +00:00
penloc: DEFINE_POINT 0, 0
2018-01-30 05:11:32 +00:00
penwidth: .byte 4
penheight: .byte 2
penmode: .byte 0
textback: .byte $7F
textfont: .addr DEFAULT_FONT
nextwinfo: .addr 0
.endproc
2017-09-11 03:40:32 +00:00
2018-03-05 05:36:00 +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
2018-01-30 04:49:42 +00:00
MGTK_CALL MGTK::OpenWindow, winfo
2017-09-13 05:01:45 +00:00
lda #0
sta selected_field
jsr draw_window
2018-01-29 16:38:23 +00:00
MGTK_CALL MGTK::FlushEvents
2017-09-13 15:09:33 +00:00
;; fall through
2017-09-13 07:04:21 +00:00
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-13 07:04:21 +00:00
;;; Input loop
2017-09-13 15:09:33 +00:00
.proc input_loop
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::GetEvent, event_params
2018-01-30 05:11:32 +00:00
lda event_params::kind
2018-02-03 04:10:19 +00:00
cmp #MGTK::event_kind_button_down
2017-09-13 07:04:21 +00:00
bne :+
jsr on_click
2017-09-13 07:04:21 +00:00
jmp input_loop
2018-02-03 04:10:19 +00:00
: cmp #MGTK::event_kind_key_down
2017-09-13 07:04:21 +00:00
bne input_loop
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc on_key
2018-01-30 04:14:34 +00:00
lda event_params::modifiers
2017-09-13 07:04:21 +00:00
bne input_loop
2018-01-30 04:14:34 +00:00
lda event_params::key
2018-02-27 04:13:18 +00:00
cmp #CHAR_RETURN
2017-09-13 07:04:21 +00:00
bne :+
2017-09-13 08:28:28 +00:00
jmp on_ok
2018-02-27 04:13:18 +00:00
: cmp #CHAR_ESCAPE
2017-09-13 07:04:21 +00:00
bne :+
jmp on_cancel
2018-02-27 04:13:18 +00:00
: cmp #CHAR_LEFT
2017-09-13 07:04:21 +00:00
beq on_key_left
2018-02-27 04:13:18 +00:00
cmp #CHAR_RIGHT
2017-09-13 07:04:21 +00:00
beq on_key_right
2018-02-27 04:13:18 +00:00
cmp #CHAR_DOWN
2017-09-13 07:04:21 +00:00
beq on_key_down
2018-02-27 04:13:18 +00:00
cmp #CHAR_UP
2017-09-13 07:04:21 +00:00
bne input_loop
on_key_up:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, up_arrow_rect
2017-09-13 08:28:28 +00:00
lda #up_rect_index
sta hit_rect_index
jsr do_inc_or_dec
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 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:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, down_arrow_rect
2017-09-13 08:28:28 +00:00
lda #down_rect_index
sta hit_rect_index
jsr do_inc_or_dec
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 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
2018-03-05 05:36:00 +00:00
;;; ============================================================
.proc on_click
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::FindWindow, event_params::xcoord
MGTK_CALL MGTK::SetPenMode, penmode_params
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetPattern, white_pattern
2018-01-30 04:49:42 +00:00
lda findwindow_params::window_id
2018-01-31 08:05:54 +00:00
cmp #da_window_id
2017-09-13 08:28:28 +00:00
bne miss
2018-01-30 04:49:42 +00:00
lda findwindow_params::which_area
bne hit
2017-09-13 08:28:28 +00:00
miss: rts
2018-01-29 05:18:00 +00:00
hit: cmp #MGTK::area_content
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
2018-02-07 02:42:00 +00:00
copy16 hit_target_jump_table,y, jump+1
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-13 08:28:28 +00:00
.proc on_ok
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 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:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 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
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 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
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, 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
2018-01-30 04:14:34 +00:00
loop: MGTK_CALL MGTK::GetEvent, event_params ; Repeat while mouse is down
2018-01-30 05:11:32 +00:00
lda event_params::kind
2018-02-03 04:10:19 +00:00
cmp #MGTK::event_kind_button_up
2017-09-13 08:28:28 +00:00
beq :+
jsr do_inc_or_dec
jmp loop
: lda hit_rect_index
cmp #up_rect_index
beq :+
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, down_arrow_rect
rts
2018-01-29 05:18:00 +00:00
: MGTK_CALL MGTK::PaintRect, 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
2018-02-07 02:42:00 +00:00
decr: copy16 #decrement_table, ptr
2017-09-13 08:28:28 +00:00
jmp go
2018-02-07 02:42:00 +00:00
incr: copy16 #increment_table, ptr
2017-09-13 08:28:28 +00:00
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
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::SetTextBG, settextbg_params
2017-09-13 08:28:28 +00:00
jmp draw_selected_field
.endproc
hit_rect_index:
.byte 0
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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
2018-02-07 02:42:00 +00:00
copy16 #str, ptr
2017-09-13 05:01:45 +00:00
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
2018-03-05 05:36:00 +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
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::CloseWindow, closewindow_params
2018-02-05 03:13:21 +00:00
DESKTOP_CALL DT_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
2018-03-05 05:36:00 +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
2018-02-07 02:42:00 +00:00
copy16 event_params::xcoord, screentowindow_params::screenx
copy16 event_params::ycoord, screentowindow_params::screeny
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::ScreenToWindow, screentowindow_params
2018-01-30 04:49:42 +00:00
MGTK_CALL MGTK::MoveTo, screentowindow_params::window
2017-09-13 08:28:28 +00:00
ldx #1
2018-02-07 02:42:00 +00:00
copy16 #first_hit_rect, test_addr
2017-09-13 08:28:28 +00:00
loop: txa
pha
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::InRect, $1000, test_addr
2017-09-13 08:28:28 +00:00
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
2018-03-05 05:36:00 +00:00
;;; ============================================================
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:
2018-01-29 05:18:00 +00:00
DEFINE_STRING {"OK ",GLYPH_RETURN} ;
2017-09-13 04:27:27 +00:00
label_cancel:
2018-01-29 05:18:00 +00:00
DEFINE_STRING "Cancel ESC"
2017-09-13 04:27:27 +00:00
label_uparrow:
2018-01-29 05:18:00 +00:00
DEFINE_STRING GLYPH_UARROW
2017-09-13 04:27:27 +00:00
label_downarrow:
2018-01-29 05:18:00 +00:00
DEFINE_STRING 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
2018-01-30 04:14:34 +00:00
.proc setpensize_params
2018-01-30 05:11:32 +00:00
penwidth: .byte 1
penheight: .byte 1
.endproc
2017-09-13 04:27:27 +00:00
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-13 07:04:21 +00:00
;;; Render the window contents
draw_window:
2018-01-30 04:49:42 +00:00
MGTK_CALL MGTK::SetPort, winfo::port
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::FrameRect, border_rect
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::SetPenSize, setpensize_params
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::FrameRect, date_rect
MGTK_CALL MGTK::FrameRect, ok_button_rect
MGTK_CALL MGTK::FrameRect, cancel_button_rect
2017-09-13 04:27:27 +00:00
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, label_ok_pos
MGTK_CALL MGTK::DrawText, label_ok
2017-09-13 04:27:27 +00:00
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, label_cancel_pos
MGTK_CALL MGTK::DrawText, label_cancel
2017-09-13 04:27:27 +00:00
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, label_uparrow_pos
MGTK_CALL MGTK::DrawText, label_uparrow
MGTK_CALL MGTK::FrameRect, up_arrow_rect
2017-09-13 04:27:27 +00:00
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, label_downarrow_pos
MGTK_CALL MGTK::DrawText, label_downarrow
MGTK_CALL MGTK::FrameRect, down_arrow_rect
2017-09-13 04:27:27 +00:00
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
2018-01-30 04:14:34 +00:00
MGTK_CALL MGTK::SetPenMode, penmode_params
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::SetPattern, 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
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, day_pos
MGTK_CALL MGTK::DrawText, day_string
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc draw_month
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, month_pos
MGTK_CALL MGTK::DrawText, spaces_string ; variable width, so clear first
MGTK_CALL MGTK::MoveTo, month_pos
MGTK_CALL MGTK::DrawText, month_string
rts
2017-09-13 15:09:33 +00:00
.endproc
2017-09-13 15:09:33 +00:00
.proc draw_year
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::MoveTo, year_pos
MGTK_CALL MGTK::DrawText, year_string
rts
2017-09-13 15:09:33 +00:00
.endproc
2018-03-05 05:36:00 +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:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, year_rect
rts
2017-09-13 15:09:33 +00:00
fill_day:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, day_rect
rts
2017-09-13 15:09:33 +00:00
fill_month:
2018-01-29 05:18:00 +00:00
MGTK_CALL MGTK::PaintRect, month_rect
rts
2017-09-13 15:09:33 +00:00
.endproc
2018-03-05 05:36:00 +00:00
;;; ============================================================
2017-09-13 15:09:33 +00:00
;;; 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
2018-03-05 05:36:00 +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
2018-03-05 05:36:00 +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 := *