6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Wed Jun 05, 2024 11:53 am

All times are UTC




Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2
Author Message
PostPosted: Sat Jul 17, 2021 6:46 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1933
Location: Sacramento, CA, USA
If you're comfortable in the land of NMOS, you can try this at only 29 bytes (untested):
Code:
DPL     =   $fd
DPH     =   $fe
primm:
      pla               ; get low part of (string address-1)
      tay
      pla               ; get high part of (string address-1)
      sta   DPH
      lda   #0
      sta   DPL
      beq   primm3
primm2:
      jsr   COUT        ; output a string char
primm3:
      iny               ; advance the string pointer
      bne   primm4
      inc   DPH
primm4:
      lda   (DPL),y     ; get string char
      bne   primm2      ; output and continue if not NUL
      lda   DPH
      pha
      tya
      pha
      rts               ; proceed at code following the NUL

If I didn't mess something up, this should work all the way back to an original Apple 1.

Edit: If you don't mind trashing A X and Y, then here's some (untested) CMOS in only 24 bytes:
Code:
DPL     =   $fd
DPH     =   $fe
primm:
      ply               ; get low part of (string address-1)
      stz   DPL
      plx               ; get high part of (string address-1)
      stx   DPH
      bra   primm3
primm2:
      jsr   COUT        ; output a string char
primm3:
      iny               ; advance the string pointer
      bne   primm4
      inc   DPH
      inx
primm4:
      lda   (DPL),y     ; get string char
      bne   primm2      ; output and continue if not NUL
      phx
      phy
      rts               ; proceed at code following the NUL

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Last edited by barrym95838 on Wed Jul 28, 2021 8:28 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 9:21 am 
Offline

Joined: Mon Jun 08, 2020 7:42 pm
Posts: 22
A further question: from https://wilsonminesco.com/stacks/inlinedData.html
What is the significance of the $103 stack address?
Code:
ISR:    PHA          ; (Later you may need to push Y also, with PHY, if the
        PHX          ; ISR uses Y anywhere. NMOS will have to go through A.)

        TSX
        LDA  103,X   ; Get the stacked status, and
        AND  #$10    ; see if the B bit is set (meaning a BRK instruction
        BNE  break   ; caused the interrupt.  If B bit is set, branch.

        <service hardware interrupt>

<further code follows>


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 9:40 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8198
Location: Midwestern USA
rascalsailor wrote:
A further question: from https://wilsonminesco.com/stacks/inlinedData.html
What is the significance of the $103 stack address?

It has to do with the expected offset of the status register (SR) on the hardware stack when it was pushed following an interrupt or the processing of a BRK instruction (a software interrupt)—SR is automatically pushed, along with the (16-bit) program counter. The actual number would depend on whether other registers were pushed before retrieving the SR copy for testing. In the example, only .X has been pushed, so the offset to SR would be 3 (the stack starts at $0100 and a total of four bytes was pushed).

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Last edited by BigDumbDinosaur on Wed Aug 04, 2021 3:06 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 10:19 am 
Offline

Joined: Mon Jun 08, 2020 7:42 pm
Posts: 22
BigDumbDinosaur wrote:
rascalsailor wrote:
A further question: from https://wilsonminesco.com/stacks/inlinedData.html
What is the significance of the $103 stack address?

(the stack starts at $0100 and a total of four bytes was pushed).

Thanks - but how can the code be sure that the stack wasn't previously used and that previous users of the stack haven't left the pointer pointing at any other stack address?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 11:23 am 
Offline

Joined: Fri Jul 09, 2021 10:12 pm
Posts: 741
TSX already copied the stack pointer into the X register, and that's being added on as well. It works so long as the stack pointer wasn't less than 3 to begin with, so is generally fine if you initialised the SP to $FF on startup. I use this technique as well because it allows the routine to be called with a simple JSR without needing any register saving at the call site, making it easy to drop in these "print statements" into existing code.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 4:17 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1933
Location: Sacramento, CA, USA
The notion of preserving register contents across subroutine calls can be a common source of bugs. You can play it safe and save everything all the time (on the 65xx that's not outrageously expensive), or you can take the extra time to decide what needs to be preserved and what doesn't. Detailed source comments should allow you or someone else to extend or maintain the code without something suddenly blowing up because "we trashed Y before we needed it".

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 5:48 pm 
Offline

Joined: Sat Jan 02, 2016 10:22 am
Posts: 197
rascalsailor wrote:
BigDumbDinosaur wrote:
rascalsailor wrote:
A further question: from https://wilsonminesco.com/stacks/inlinedData.html
What is the significance of the $103 stack address?

(the stack starts at $0100 and a total of four bytes was pushed).

Thanks - but how can the code be sure that the stack wasn't previously used and that previous users of the stack haven't left the pointer pointing at any other stack address?

I think the key thing to remember here, with the 6502/65C02 the because stack pointer is 8 bits wide, the stack can ONLY be in the $100 to $1FF range. There is no way for a prgrammer to move it out of that range.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 22 posts ]  Go to page Previous  1, 2

All times are UTC


Who is online

Users browsing this forum: Google [Bot] and 23 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: