[Coco] LWASM "Hello World" for OS 9.
johnmarkmelanie at gmail.com
johnmarkmelanie at gmail.com
Sat Oct 7 21:43:02 EDT 2023
All,
See below.
Note: end Start
This is needed to make it work.
For Hello World see:
Start, Introduction, and Msg1.
-John Mark Mobley
-------
;Name: MAGICSQR.BIN
;Purpose: To Solve a 3X3 Magic Square
;By: John Mark Mobley
;Date: 07-06-2015
;Run Environment: Tandy Color Computer 1 with a 6809 microprocessor
;Emulator: XRoar
;RAM: 4k
;ROM: Color BASIC
;Development Environment: IBM Compatible PC, Linux, LWTOOLS, and ToolShed
;Build Script:
; #!/bin/bash
; lwasm magicsquare.asm -b -omagicsquare.bin
; decb copy -2 -b -r magicsquare.bin cocotest.dsk,MAGICSQR.BIN
; decb dir cocotest.dsk:0
; makewav -r -c -nMAGICSQR -2 -b -oMagicSqr.wav magicsquare.bin
; makewav -r -c -nMAGICSQR -2 -b -k -oMagicSqr.cas magicsquare.bin
pragma cescapes
org $0800
Backspace equ 8
;Reserve variable space in RAM
P9 rmb 1
P8 rmb 1
P7 rmb 1
P6 rmb 1
P5 rmb 1
P4 rmb 1
P3 rmb 1
P2 rmb 1
N1 rmb 1
N2 rmb 1
N3 rmb 1
N4 rmb 1
N5 rmb 1
N6 rmb 1
N7 rmb 1
N8 rmb 1
N9 rmb 1
T rmb 1
;ASCII Ruler
; 1 1 2 2 3
; ----5----0----5----0----5----0--
;*********************************************
Msg1 fcc " MAGIC SQUARE SOLVER\r"
fcc " BY: JOHN MARK MOBLEY\r"
fcc " DATE: 07-06-2015\r"
fcc "\r"
fcc "THIS PROGRAM WILL FIND EVERY\r"
fcc "SOLUTION FOR A 3X3 MAGIC SQUARE."
fcc "THE IDEA IS TO ARRANGE THE\r"
fcc "NUMBERS 1-9 INTO A TIC-TAC-TOE\r"
fcc "BOARD SUCH THAT EACH ROW,\r"
fcc "COLUMN, AND DIAGONAL ADD UP TO\r"
fcc "15.\r\0"
Msg2 fcc "SEE THE EXAMPLE BELOW.\r"
fcc "\r"
fcc " /- 8+5+2=15 DIAGONAL\r"
fcc " 4 9 2 - 15 ACROSS\r"
fcc " 3 5 7 - 15 ACROSS\r"
fcc " 8 1 6 - 15 ACROSS\r"
fcc " ! ! ! - 4+5+6=15 DIAGONAL\r"
fcc " 15 15 15 - DOWN\r\0"
Msg3 fcc "\r"
fcc "THE PROGRAM WILL NOW GENERATE A\r"
fcc "PERMUTATION OF 9 TAKEN 9 AT A\r"
fcc "TIME AND TEST EACH PERMUTATION\r"
fcc "TO SEE IF IT IS A SOLUTION FOR\r"
fcc "A 3X3 MAGIC SQUARE. THEN IT\r"
fcc "WILL PRINT ALL SOLUTIONS.\r"
fcc "\r\0"
Msg9 fcc "\rPRESS A KEY TO CONTINUE\r\0"
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* Start... Main Control Section
*
Start lda #0 Print to screen
sta $006F "
jsr Introduction
jsr PermutationGenerator
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* Introduction... Print the welcome screen
*
Introduction
jsr $A928 Clear Screen
ldx #Msg1 Print Message 1
jsr PrintMsg "
jsr WaitForKeyPress Wait for key press
ldx #Msg2 Print Message 2
jsr PrintMsg "
jsr WaitForKeyPress Wait for key press
ldx #Msg3 Print Message 3
jsr PrintMsg "
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* PermutationGenerator... This program will generate a permutation of 9 taken
* 9 at a time. N1-N9 hold the numbers 1-9. The order of the numbers is
* rearranged to every possibility.
*
PermutationGenerator
;init RAM varibles
lda #1 N1=1
sta N1 "
lda #2 N2=2
sta N2 "
lda #3 N3=3
sta N3 "
lda #4 N4=4
sta N4 "
lda #5 N5=5
sta N5 "
lda #6 N6=6
sta N6 "
lda #7 N7=7
sta N7 "
lda #8 N8=8
sta N8 "
lda #9 N9=9
sta N9 "
ForP9I lda #9 for P9=9 to 1 step -1
sta P9
ForP9L
ForP8I lda #8 for P8=8 to 1 step -1
sta P8
ForP8L
ForP7I lda #7 for P7=7 to 1 step -1
sta P7
ForP7L
ForP6I lda #6 for P6=6 to 1 step -1
sta P6
ForP6L
ForP5I lda #5 for P5=5 to 1 step -1
sta P5
ForP5L
ForP4I lda #4 for P4=4 to 1 step -1
sta P4
ForP4L
ForP3I lda #3 for P3=3 to 1 step -1
sta P3
ForP3L
ForP2I lda #2 for P2=2 to 1 step -1
sta P2
ForP2L
jsr MagicSquareTest
ldb N2 Rotate 2 bytes
jsr Rotate2 "
NextP2 dec P2 next P2
bne ForP2L "
ldb N3 Rotate 3 bytes
jsr Rotate3 "
NextP3 dec P3 next P3
bne ForP3L "
ldb N4 Rotate 4 bytes
jsr Rotate4 "
NextP4 dec P4 next P4
bne ForP4L "
ldb N5 Rotate 5 bytes
jsr Rotate5 "
NextP5 dec P5 next P5
bne ForP5L "
ldb N6 Rotate 6 bytes
jsr Rotate6 "
NextP6 dec P6 next P6
bne ForP6L "
ldb N7 Rotate 7 bytes
jsr Rotate7 "
NextP7 dec P7 next P7
bne ForP7L "
ldb N8 Rotate 8 bytes
jsr Rotate8 "
NextP8 dec P8 next P8
bne ForP8L "
ldb N9 Rotate 9 bytes
jsr Rotate9 "
NextP9 dec P9 next P9
bne ForP9L "
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* RotateX... Rotate X Bytes
*
* Example 1:
* ldb N2 Rotate 2 bytes
* jsr Rotate2 "
*
* Example 2:
* ldb N9 Rotate 9 bytes
* jsr Rotate9 "
*
Rotate9 lda N8 N9=N8
sta N9 "
Rotate8 lda N7 N8=N7
sta N8 "
Rotate7 lda N6 N7=N6
sta N7 "
Rotate6 lda N5 N6=N5
sta N6 "
Rotate5 lda N4 N5=N4
sta N5 "
Rotate4 lda N3 N4=N3
sta N4 "
Rotate3 lda N2 N3=N2
sta N3 "
Rotate2 lda N1 N2=N1
sta N2 "
stb N1 N1=b
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* MagicSquareTest... Test to see if it adds up to the same number when adding
* each row, column, and diagonal. If all match, then print the magic squrare.
*
* Layout:
* N1, N2, N3
* N4, N5, N6
* N7, N8, N9
*
MagicSquareTest
lda N1 T=N1+N2+N3
adda N2 "
adda N3 "
sta T "
lda N4 A=N4+N5+N6
adda N5 "
adda N6 "
cmpa T exit if A<>T
bne MST99 "
lda N7 A=N7+N8+N9
adda N8 "
adda N9 "
cmpa T exit if A<>T
bne MST99 "
lda N1 A=N1+N4+N7
adda N4 "
adda N7 "
cmpa T exit if A<>T
bne MST99 "
lda N2 A=N2+N5+N8
adda N5 "
adda N8 "
cmpa T exit if A<>T
bne MST99 "
lda N3 A=N3+N6+N9
adda N6 "
adda N9 "
cmpa T exit if A<>T
bne MST99 "
lda N1 A=N1+N5+N9
adda N5 "
adda N9 "
cmpa T exit if A<>T
bne MST99 "
lda N3 A=N3+N5+N7
adda N5 "
adda N7 "
cmpa T exit if A<>T
bne MST99 "
jsr PrintMagicSquare
MST99 rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* PrintMagicSquare... Print the magic square
*
* Layout:
* N1 N2 N3
* N4 N5 N6
* N7 N8 N9
*
PrintMagicSquare
lda N1 Print N1
jsr PrintNum "
lda N2 Print N2
jsr PrintNum "
lda N3 Print N3
jsr PrintNum "
lda #13 Print a carriage return
jsr [$A002] "
lda N4 Print N4
jsr PrintNum "
lda N5 Print N5
jsr PrintNum "
lda N6 Print N6
jsr PrintNum "
lda #13 Print a carriage return
jsr [$A002] "
lda N7 Print N7
jsr PrintNum "
lda N8 Print N8
jsr PrintNum "
lda N9 Print N9
jsr PrintNum "
lda #13 Print a carriage return
jsr [$A002] "
lda #13 Print a carriage return
jsr [$A002] "
jsr WaitForKeyPress
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* PrintNum... Print the value of (a). Where (a) is a value 0 to 9.
*
* Example:
* lda N1
* jsr PrintNum
*
PrintNum
ora #$30 Make ASCII
jsr [$A002] PutChar
lda #$20 Print a space
jsr [$A002] "
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* PrintMsg... Print a text message.
*
* Example:
* ldx #Msg1
* jsr PrintMsg
*
PrintMsg ;do
lda ,x+ ;read char, and incx
beq Print99 ;exit loop if 0
jsr [$A002] ;PutChar
bra PrintMsg ;while 1
Print99 rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* WaitForKeyPress... Wait for a key press
*
WaitForKeyPress
ldx #Msg9 Print CHR$(13);"PRESS A KEY TO CONTINUE"
jsr PrintMsg "
WFKP01 jsr [$A000] If Inkey$="" THEN goto WFKP01
tsta "
beq WFKP01 "
ldb #64 repeat 64 times
lda #Backspace char=Backspace
jsr PrintRepeatChar
rts
*---|----1----|----2----|----3----|----4----|----5----|----6----|----7----|----8
* PrintRepeatChar... Print the char stored in (a) (b) times
*
* Example:
* ldb #32 repeat 32 times
* lda #'=' char='='
* jsr PrintRepeatChar
*
PrintRepeatChar ;for b=? to 1 step-1
PRC01 jsr [$A002] ;PutChar
decb ;next b
bne PRC01 ;"
rts
end Start
-------
-John Mark Mobley
-----Original Message-----
From: Coco <coco-bounces at maltedmedia.com> On Behalf Of L. Curtis Boyle via Coco
Sent: Thursday, September 21, 2023 10:39 AM
To: CoCoList for Color Computer Enthusiasts <coco at maltedmedia.com>
Cc: L. Curtis Boyle <curtisboyle at sasktel.net>
Subject: Re: [Coco] LWASM "Hello World" for OS 9.
I can’t speak for LWASM and what change would be needed using it specifically, but here is on for the level 1/2 assembler ASM:
nam Hello
ttl program module
* Use NitrOS9/EOU definition files
ifp1
use /dd/defs/deffile
endc
* From here to MOD pseudo op is for setting up the OS9 module header
* information. For a normal assembly language user program, the only
* thing you might change is the rev (revision; part of 'At/Rv' seen in
* IDENT information).
tylg set Prgrm+Objct
atrv set ReEnt+rev
rev set $01
mod eom,name,tylg,atrv,start,size
u0000 rmb 1 scratch var (unused in this example)
size equ .
name fcs /Hello/
fcb $01 Edition # (I usually this for internal version #)
* Text message to print
Message fcc 'Hello World'
fcb C$CR
MsgSize equ *-Message Message size
start lda #1 Standad output path (normally the screen)
leax Message,pcr Point to message to print for I$WritLn
ldy #MsgSize Size of message to print for I$WritLn
os9 I$WritLn Print it
clrb No error to report
os9 F$Exit Exit our tests program with no error
emod
eom equ *
end
> On Sep 21, 2023, at 5:34 AM, coco--- via Coco <coco at maltedmedia.com> wrote:
>
> All
>
> I found a LWASM "Hello World" example for 6809 assembly language in
> RS-DOS at
> https://nowhereman999.wordpress.com/2017/06/19/coco-6809-assembly-on-a
> -modern-computer/ He focuses on MAME and using the MAME debugger which
> I am not interested in at this point as I use Vcc and have had little
> success with MAME.
>
> Could anyone give me an assembly language source example "Hello World"
> for OS 9 using LWASM ?
>
> Charlie
>
> --
> Coco mailing list
> Coco at maltedmedia.com
> https://pairlist5.pair.net/mailman/listinfo/coco
>
--
Coco mailing list
Coco at maltedmedia.com
https://pairlist5.pair.net/mailman/listinfo/coco
More information about the Coco
mailing list