Skip to content

Commit

Permalink
New DA: Message
Browse files Browse the repository at this point in the history
Shows a scrolling message on the screen. Type anything to replace the
default text. Left and right arrows change the velocity.
  • Loading branch information
inexorabletash committed Mar 11, 2024
1 parent f02cd35 commit 8915b00
Show file tree
Hide file tree
Showing 22 changed files with 270 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ Project Page: https://github.com/a2stuff/a2d
* New Screen Saver: Helix.
* Electric Duet Preview: Detect Mockingboard and The Cricket!, and use for playback if found.
* New DA: Benchmark - measures CPU speed using VBL.
* New Screen Saver: Message


### Misc
Expand Down
2 changes: 2 additions & 0 deletions desk.acc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@
* Displays the current time.
* [Matrix](matrix.s)
* Digital rain.
* [Message](message.s)
* Scrolls the typed message across the screen..
* [Rod's Pattern](rods.pattern.s)
* Classic Apple II lo-res demo.

Expand Down
1 change: 1 addition & 0 deletions desk.acc/TARGETS
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ helix apple.menu/screen.savers optional
invert apple.menu/screen.savers optional
matrix apple.menu/screen.savers optional
melt apple.menu/screen.savers optional
message apple.menu/screen.savers optional
rods.pattern apple.menu/screen.savers optional
eyes apple.menu/toys optional
neko apple.menu/toys optional
Expand Down
248 changes: 248 additions & 0 deletions desk.acc/message.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
;;; ============================================================
;;; MESSAGE - Desk Accessory
;;;
;;; The typed message scrolls across the screen
;;; ============================================================

.include "../config.inc"
RESOURCE_FILE "message.res"

.include "apple2.inc"
.include "../inc/apple2.inc"
.include "../inc/macros.inc"
.include "../mgtk/mgtk.inc"
.include "../common.inc"
.include "../desktop/desktop.inc"

;;; ============================================================

DA_HEADER
DA_START_AUX_SEGMENT

;;; ============================================================

.proc AuxStart
;; Run the DA
jmp Init
.endproc ; AuxStart

;;; ============================================================
;;; Resources

kFontHeight = 11

delta: .word AS_WORD(-3)
DEFINE_POINT text_pos, kScreenWidth, (kScreenHeight + kFontHeight)/2

placeholder_flag:
.byte $80

kMaxStringLength = 48

buf: .byte res_string_message_placeholder
.res kMaxStringLength - (* - buf),0

font: .incbin "../mgtk/fonts/ATHENS"

.params text_params
data: .addr buf
length: .byte .strlen(res_string_message_placeholder)
width: .word 0 ; for `TextWidth` call
.endparams

.params spaces_params
data: .addr spaces
length: .byte 50
spaces: .res 50, ' '
.endparams

DEFINE_RECT rect, 0, (kScreenHeight - kFontHeight)/2, kScreenWidth-1, (kScreenHeight + kFontHeight)/2

event_params: .tag MGTK::Event

notpencopy: .byte MGTK::notpencopy
textbg: .byte 0

grafport: .tag MGTK::GrafPort


;;; ============================================================
;;; DA Init

.proc Init
MGTK_CALL MGTK::HideCursor

MGTK_CALL MGTK::InitPort, grafport
MGTK_CALL MGTK::SetPort, grafport

MGTK_CALL MGTK::SetPenMode, notpencopy
MGTK_CALL MGTK::PaintRect, grafport + MGTK::GrafPort::maprect

MGTK_CALL MGTK::SetFont, font
MGTK_CALL MGTK::SetTextBG, textbg

MGTK_CALL MGTK::FlushEvents
FALL_THROUGH_TO InputLoop
.endproc ; Init

;;; ============================================================
;;; Main Input Loop

.proc InputLoop
MGTK_CALL MGTK::GetEvent, event_params
lda event_params + MGTK::Event::kind
cmp #MGTK::EventKind::key_down ; any key?
beq HandleKeyDown
cmp #MGTK::EventKind::button_down ; was clicked?
beq exit

jsr Animate
jmp InputLoop

exit:
MGTK_CALL MGTK::RedrawDeskTop

MGTK_CALL MGTK::DrawMenuBar
JSR_TO_MAIN JUMP_TABLE_HILITE_MENU

MGTK_CALL MGTK::ShowCursor
rts ; exits input loop
.endproc ; InputLoop

;;; ============================================================
;;; Handle Key

.proc HandleKeyDown
lda event_params + MGTK::Event::key
cmp #CHAR_DELETE
beq backspace
cmp #' '
bcs printable

;; --------------------------------------------------
;; Non-printable
cmp #CHAR_ESCAPE
beq InputLoop::exit

cmp #CHAR_LEFT
IF_EQ
dec16 delta
jmp InputLoop
END_IF

cmp #CHAR_RIGHT
IF_EQ
inc16 delta
jmp InputLoop
END_IF

jmp InputLoop

;; --------------------------------------------------
;; Printable

printable:
bit placeholder_flag
IF_NS
ldx #0
stx text_params::length
stx placeholder_flag
END_IF

ldx text_params::length
cpx #kMaxStringLength
IF_LT
sta buf,x
inc text_params::length
END_IF

jmp InputLoop

;; --------------------------------------------------
;; Backspace

backspace:
bit placeholder_flag
IF_NS
ldx #0
stx text_params::length
stx placeholder_flag
END_IF

lda text_params::length
IF_NOT_ZERO
dec text_params::length
END_IF

jmp InputLoop

.endproc ; HandleKeyDown

;;; ============================================================
;;; Animate

.proc Animate
MGTK_CALL MGTK::MoveTo, text_pos

MGTK_CALL MGTK::PaintRect, rect

lda text_params::length
IF_ZERO
copy16 #0, rect::x1
copy16 #kScreenWidth-1, rect::x2
MGTK_CALL MGTK::PaintRect, rect
ELSE
MGTK_CALL MGTK::DrawText, text_params
MGTK_CALL MGTK::TextWidth, text_params

;; Clear before/after
copy16 #0, rect::x1
sub16 text_pos::xcoord, #1, rect::x2
scmp16 rect::x1, rect::x2
IF_NEG
MGTK_CALL MGTK::PaintRect, rect
END_IF

add16 text_pos::xcoord, text_params::width, rect::x1
copy16 #kScreenWidth-1, rect::x2
scmp16 rect::x2, rect::x1
IF_NEG
MGTK_CALL MGTK::PaintRect, rect
END_IF

END_IF

add16 text_pos::xcoord, delta, text_pos::xcoord

lda delta+1
IF_NS
tmp := $06
add16 text_pos::xcoord, text_params::width, tmp
lda tmp+1
IF_NS
copy16 #kScreenWidth-1, text_pos::xcoord
END_IF
ELSE
scmp16 text_pos::xcoord, #kScreenWidth
IF_POS
sub16 #0, text_params::width, text_pos::xcoord
END_IF
END_IF

rts
.endproc ; Animate

;;; ============================================================

DA_END_AUX_SEGMENT

;;; ============================================================

DA_START_MAIN_SEGMENT

JSR_TO_AUX aux::AuxStart
rts

DA_END_MAIN_SEGMENT

;;; ============================================================
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.da
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Udskriv.katalog"
.define res_filename_change_type "skift.type"
.define res_filename_benchmark "benchmark"
.define res_filename_message "Besked"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.de
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Katalog.drucken"
.define res_filename_change_type "typ.andern"
.define res_filename_benchmark "benchmark"
.define res_filename_message "Nachricht"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.en
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Print.Catalog"
.define res_filename_change_type "Change.Type"
.define res_filename_benchmark "Benchmark"
.define res_filename_message "Message"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.es
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Impr.catalogo"
.define res_filename_change_type "cambiar.tipo"
.define res_filename_benchmark "referencia"
.define res_filename_message "Mensaje"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.fr
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Impr.catalogue"
.define res_filename_change_type "modifier.type"
.define res_filename_benchmark "reference"
.define res_filename_message "Message"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.it
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Stampa.Catalogo"
.define res_filename_change_type "modifica.tipo"
.define res_filename_benchmark "benchmark"
.define res_filename_message "Messaggio"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.nl
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "print.catalogus"
.define res_filename_change_type "wijzig.type"
.define res_filename_benchmark "benchmark"
.define res_filename_message "Bericht"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.pt
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Impr.Catalogo"
.define res_filename_change_type "alterar.tipo"
.define res_filename_benchmark "referencia"
.define res_filename_message "Mensagem"
1 change: 1 addition & 0 deletions desk.acc/res/filenames.res.sv
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
.define res_filename_print_catalog "Skriv.katalog"
.define res_filename_change_type "andra.typ"
.define res_filename_benchmark "benchmark"
.define res_filename_message "Meddelande"
1 change: 1 addition & 0 deletions desk.acc/res/message.res.da
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Skriv en besked ..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.de
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Geben Sie eine Nachricht ein ..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.en
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Type a message..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.es
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Escriba un mensaje ..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.fr
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Tapez un message ..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.it
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Scrivi un messaggio..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.nl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Type een bericht..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.pt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Digite uma mensagem..."
1 change: 1 addition & 0 deletions desk.acc/res/message.res.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.define res_string_message_placeholder "Skriv ett meddelande..."

0 comments on commit 8915b00

Please sign in to comment.