6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Sep 21, 2024 8:20 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: Sun Jun 08, 2014 7:22 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
Before:
Code:
twoplus
2    clc
3    lda tos
2    adc #2
3    sta tos
3/2  bcc twoplus01
0/5  inc tos+1
twoplus01
3    jmp next ;[14 bytes/16 cycles]

twominus
2    sec
3    lda tos
2    sbc #2
3    sta tos
3/2  bcs twominus01
0/5  dec tos+1
twominus01
3    jmp next ;[14 bytes/16 cycles]

After:
Code:
twoplus
2    lda #2
twopm
3    ldy tos+1
2    clc
3    adc tos
3/2  bcc twoplus01
0/2  iny
twoplus01
3    jmp put   ;[13 bytes/25 cycles]         ; TOS = YA

twominus
5    dec tos+1
2    lda #$fe
3    bne twopm ;[6 bytes/29 cycles]         ; bra

put
3    sty tos+1
3    sta tos
3    jmp next


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 08, 2014 9:10 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1948
Location: Sacramento, CA, USA
Does your new 'detached header' structure allow you to overlap words? If so, you may be able to take advantage of this in several primitives, right?

Another thing just occurred to me. You're carrying a modified SWEET16, so could you pull some tricks by putting TOS in R0?

Code:
twoplus:
        BRK  ; to SWEET16
        INR  0
        INR  0
        RTN
        JMP  next


Mike


Last edited by barrym95838 on Sun Jun 08, 2014 9:31 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 08, 2014 9:18 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
barrym95838 wrote:
Does your new 'detached header' structure allow you to overlap words? If so, you may be able to take advantage of this in several primitives, right?

Mike


With nothing but code in the dictionary, fallthrough works. Here's what I did with DROP 2DROP 3DROP 4DROP and poptwo pop put used by primitives. Mostly I'm focusing right now on getting FIND and the outer interpreter to work again, so I can change my cold banner message to something other than
.asc "VERSION PRE-ALPHA 2014-06-02",CR
.asc "455 SACK OF ROME: VANDALS ENTER ROME,",CR
.asc " AND PLUNDER THE CITY FOR TWO WEEKS",CR

Code:
;--------------------------------------------------------------
;
;       2DROP
;
#ifdef HEADERS
twodroplfa
    .byt $de,$ad
    .byt (twodrop-*-1)|bit7
    .asc "2DRO","P"|bit7
#endif
twodrop

poptwo
    inx
;--------------------------------------------------------------
;
;       DROP   ( n -- )
;
; * 83 nucleus
;
#ifdef HEADERS
droplfa
    .byt $de,$ad
    .byt (drop-*-1)|bit7
    .asc "DRO","P"|bit7
#endif
drop

pops
    ldy stackh,x
    lda stackl,x
    inx
put
    sty tos+1
    sta tos
    jmp next

;--------------------------------------------------------------
;
;      4DROP   ( -- )
;
; description
;
#ifdef HEADERS
fourdroplfa
   .byt $de,$ad
   .byt (fourdrop-*-1)|bit7
   .asc "4DRO","P"|bit7
#endif
fourdrop
   inx

;--------------------------------------------------------------
;
;       3DROP   ( a b c -- )
;
; * 83 nucleus
;
#ifdef HEADERS
threedroplfa
    .byt $de,$ad
    .byt (threedrop-*-1)|bit7
    .asc "3DRO","P"|bit7
#endif
threedrop
    inx
    bne poptwo


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 08, 2014 9:23 pm 
Offline

Joined: Sun Nov 08, 2009 1:56 am
Posts: 395
Location: Minnesota
Regarding your original post, if small size rather than highest speed is your aim, how about this:

Code:
twominus:   ; 19 bytes
  dec tos+1
  lda #-2   ; aka #$FE, or any number of other ways to specify it
  .byte $CD ; 'cmp absolute', although 'bit absolute' is also popular
twoplus:    ; 14 bytes
  lda #2
  clc
  adc tos
  sta tos
  bcc :+
  inc tos+1
:
  jmp next


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 08, 2014 9:38 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
Well played, teamtempest! Winner!
Code:
;--------------------------------------------------------------
;
;       3-
;
#ifdef HEADERS
threeminuslfa
    .byt $de,$ad
    .byt (threeminus-*-1)|bit7
    .asc "3","-"|bit7
#endif
threeminus
    lda #$fd
   .byt $2c ; BIT absolute instruction, fall through to twominus
;--------------------------------------------------------------
;
;       2-
;
#ifdef HEADERS
twominuslfa
    .byt $de,$ad
    .byt (twominus-*-1)|bit7
    .asc "2","-"|bit7
#endif
twominus
    lda #$fe
    dec tos+1
    .byt $2c ; BIT absolute instruction, fall through to twoplus
;--------------------------------------------------------------
;
;       2+
;
#ifdef HEADERS
twopluslfa
    .byt $de,$ad
    .byt (twoplus-*-1)|bit7
    .asc "2","+"|bit7
#endif
twoplus
    lda #2
nplus
    clc
    adc tos
    sta tos
    bcc twoplus01
    inc tos+1
twoplus01
    jmp next

;--------------------------------------------------------------
;
;       3+
;
#ifdef HEADERS
threepluslfa
    .byt $de,$ad
    .byt (threeplus-*-1)|bit7
    .asc "3","+"|bit7
#endif
threeplus
    lda #3
   bne nplus               ; bra


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 08, 2014 10:01 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
barrym95838 wrote:
Does your new 'detached header' structure allow you to overlap words? If so, you may be able to take advantage of this in several primitives, right?

Another thing just occurred to me. You're carrying a modified SWEET16, so could you pull some tricks by putting TOS in R0?

Code:
twoplus:
        BRK  ; to SWEET16
        INR  0
        INR  0
        RTN
        JMP  next


Mike


JMP NEXT is a new Sweet16 opcode, and LDD/POPD have the side effect of double-incrementing or double-decrementing the pointer, so these would work. I'm not going to use them because 2+ 2- are invoked fairly often and the CPU overhead of doing this in Sweet16 would be hundreds of cycles, much higher than I'm willing to tolerate for saving a few bytes. It's okay for code that runs infrequently, some compiler code, or code that runs at human speed (editor functions) but I'm avoiding it in the parts that should run fast. It's a balancing act. Potential unwanted side effects could occur if TOS is pointing at an I/O chip like the 6522 VIA, where hitting it with a read does other things on the chip
Code:
twoplus
        brk ; Sweet16
        .byt ldd | TOS  ; TOS is in R4, I don't always want to modify TOS. R0 will be discarded.
        .byt nxt
twominus
        brk ; Sweet16
        .byt popd | TOS
        .byt nxt
threeminus
        brk ; Sweet16
        .byt popd | TOS
        .byt dcr | TOS
        .byt nxt
threeplus
        brk ; Sweet16
        .byt ldd | TOS
        .byt inr | TOS
        .byt nxt


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 09, 2014 3:50 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
chitselb wrote:
Potential unwanted side effects could occur if TOS is pointing at an I/O chip like the 6522 VIA, where hitting it with a read does other things on the chip

Those unwanted side effects can also result from the trick teamtempest used. I don't condemn the idea, but it's good to be aware of what'll happen.

Code:
  .byte $CD ; 'cmp absolute', although 'bit absolute' is also popular
twoplus:
  lda #2
is one byte shorter (and one cycle slower) than
Code:
  BRA $+2
twoplus:
  lda #2
but results in a spurious read. In this case the "address" that gets read is lda #2, or $02A9. If you edit the code then of course some other address could get hit. One way or the other it could really bite you if you're not careful!

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 09, 2014 7:32 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10938
Location: England
Would it be better to have machine code primitives for I/O access? I know the 6502 has memory-mapped I/O, but that doesn't mean it's wise to allow arbitrary access as if the I/O were memory.


Top
 Profile  
Reply with quote  
PostPosted: Mon Jun 09, 2014 12:45 pm 
Offline

Joined: Sat Aug 21, 2010 7:52 am
Posts: 231
Location: Arlington VA
In my situation, I'm letting the PET Kernel ROM do most of the heavy lifting. I'm reusing it's clock, tape, disk, screen and keyboard I/O ROM as much as possible.

As for the BIT branch trick, I've given it some thought and decided it's extremely unlikely, and not worth worrying about, that it will hit something bad and bite me in the butt. There are chips at $E810-E813 (PIA1), $E820-E823 (PIA2), $E840-E84F (VIA), and possibly a CRTC controller (which I do not have) starting at $E880. The addresses are incompletely decoded so lots of opcodes would work, either directly or at a 'mirror' address. The reason I don't worry at all is that the second byte immediately following would have to be $E8-EF to hit the I/O page, which is in the middle of the zero page screen linewrap table stored from $E0-$F8. Forth doesn't (and shouldn't) do a lot of error checking, instead it takes more of a go-fast no-bozos approach. If it fails, I get to figure out why and fix it.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 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: