Advertisement
Guest User

Untitled

a guest
Mar 4th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .word $1000
  2. *=$1000
  3. dp = $c0
  4. sp = $c2
  5. cs = $c4
  6.  
  7.     sei
  8.     lda #<data
  9.     sta sp
  10.     lda #>data
  11.     sta sp+1
  12.    
  13.     lda #<$0400
  14.     sta dp
  15.     lda #>$0400
  16.     sta dp+1
  17.  
  18.     jsr decrunch
  19.     jmp *
  20.    
  21. decrunch_done:
  22.     rts
  23.  
  24. literal_run
  25. literal_loop
  26.     iny
  27.     lda (sp),y
  28.     sta (dp),y
  29.     dex
  30.     bmi literal_loop
  31.  
  32.     tya
  33.     pha
  34.     clc
  35. increase_dp_by_a_and_sp_by_tos_plus_one
  36.     adc dp
  37.     sta dp
  38.     bcc l1
  39.     inc dp+1
  40. l1
  41.     pla
  42. update_sp
  43.     sec
  44.     adc sp
  45.     sta sp
  46.     bcc l2
  47.     inc sp+1
  48. l2
  49.  
  50. decrunch
  51. next_command
  52.     ldy #0
  53.     lda (sp),y
  54.     tax
  55.     beq decrunch_done
  56.    
  57.     asl
  58.     bcc far_copy
  59.     bpl literal_run
  60.  
  61. near_copy
  62.     ldx #$07   ; clear high byte of -ve offset. Also ensures copy_loop doesn't loop.
  63.     .byt $f0  ; beq (not taken) to skip over the iny
  64. far_copy
  65.     iny
  66.     ; carry is set for near_copy, clear for far_copy
  67.  
  68.     lda (sp),y ;fetch second byte (or for near copy, refetch first).  This is low 8 bits of offset.
  69.     adc dp
  70.     sta cs
  71.     txa
  72.     ora #$f8
  73.     adc dp+1
  74.     sta cs+1
  75.     tya
  76.     pha  ; save opcode length to stack
  77.     ldy#1
  78.     lda (cs),y
  79.     sta (dp),y
  80.  
  81.     ;sec ;to replace sbx
  82.     ;sec
  83. copy_loop:
  84.     iny
  85.     lda (cs),y
  86.     sta (dp),y
  87.     txa   ; spend an extra 2 cycles per byte here to save 10 in the bitfield extraction. A win on average
  88.     ;sbx#8
  89.     sbc #8
  90.     txa
  91.     bpl copy_loop
  92.     tya
  93.     bcc increase_dp_by_a_and_sp_by_tos_plus_one ; always taken.
  94. edecrunch
  95.     rts
  96.    
  97. data
  98. .bin 0,0,"screen.tuc"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement