Nakazoto / Hellorld

A collection of the greatest programming on the planet!
21 stars 4 forks source link

Hellorld! on a Commodore PET 2001 (too modern?) #8

Open rickreynolds1969 opened 1 year ago

rickreynolds1969 commented 1 year ago

I know David wanted obscure hobby computers mainly, and used the C64 as an example of what he's not particularly interested in. The PET is nowhere near as ubiquitous as the C64 or VIC20, so I hope it can count as a submission. If not, toss this submission.

This is hellorld done in PET 6502 assembler, using a print routine that I created for another project. So it involves setting source and location pointers and then looping through the PETSCII code to print the message to the screen at the lower left corner.

I ran it on real hardware and everything! :) The PET 2001 shown is one I restored to working order.

IMG_2778

6502 Assembler code for DASM

#processor 6502
#seg code

;
; Definitions
;

MESSAGELOC = $83C0  ; pointer to the location in screen memory where the message will appear (last line, first col)
SOURCEPTR = $51     ; zero page pointer to the text that will be printed on the screen (used by print routine)
SCREENPTR = $53     ; zero page pointer to the location on the screen where the text should appear (used by print routine)
EOM = 254           ; End of message code

;
; Recipe to setup the code with one basic line:
;
; 10 SYS 1040
;
; These three lines put that basic one-liner into the start of basic memory
; (on the PET that's at $0400).  Memory location 1040 (decimal) is $0410 (hex).
;
              org $0401
;                  0400   01   02   03   04   05   06   07
;                        [040E is addr of next basic line, which is end of program]
;                               |  [ 10 is line number - 0010 ]
;                               |         |  [ SYS ]
;                               |         |    |  [ space ]
;                               |         |    |    |  [ "1" ]
;                               |         |    |    |    |
              .byte      $0E, $04, $0A, $00, $9E, $20, $31

;                  0408   09   0a   0b   0c   0d   0e   0f
;                   [ "0" ]
;                     |  [ "4" ]
;                     |    |  [ "0" ]
;                     |    |    |  [ end of basic statement "00" ]
;                     |    |    |    |      [ end of basic program "00 00"]
;                     |    |    |    |                   |
              .byte $30, $34, $30, $00, $00, $00, $00, $00

; --------------------------------------------------------------------------------------------------

              org $0410
              cld                 ; unset "decimal" mode for additions

              ; set the SOURCEPTR to point to the MESSAGE data block
              lda #<MESSAGE
              sta SOURCEPTR
              lda #>MESSAGE
              sta SOURCEPTR+1

              ; set the SCREENPTR to point to where we want the message to be printed
              lda #<MESSAGELOC
              sta SCREENPTR
              lda #>MESSAGELOC
              sta SCREENPTR+1

              ; call our print routine
              jsr PRINTSTR

              ; return back to BASIC
              rts

              ;     H  E   L   L   O   R   L  D   !
MESSAGE:      .byte 8, 5, 12, 12, 15, 18, 12, 4, 33, EOM

PRINTSTR:     ldy #0
PRINTLOOP:    lda (SOURCEPTR),y     ; get the next letter
              cmp #EOM              ; check for end of message
              beq PRINTRET

              sta (SCREENPTR),y
              iny
              jmp PRINTLOOP
PRINTRET:     rts