Advertisement
NovaYoshi

miuchiz memory explorer

Feb 4th, 2019
567
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .include "hardware.s"
  2. .macpack generic
  3. .macpack longbranch
  4. .segment "ZEROPAGE"
  5. Pointer: .res 2     ; Temporary variable for pointers
  6. DrawX: .res 1       ; X pixel coordinate
  7. DrawY: .res 1       ; Y poxel coordinate
  8.  
  9. TextIdx: .res 1     ; Index used when filling TextBuf
  10. CursorX: .res 1     ; Which digit is selected
  11.  
  12. ; Port monitor stuff
  13. ViewAddress: .res 2 ; 32-byte preview pointer
  14.  
  15. Address: .res 2     ; Address entered by the user, in big endian
  16. WriteValue: .res 1  ; Value to write when pressing action
  17. ReadValue:  .res 1  ; Value read by pressing menu
  18.  
  19. .segment "BSS"
  20. keydown: .res 2     ; Keys pressed
  21. keylast: .res 2     ; Keys pressed last frame
  22. keynew:  .res 2     ; Keys pressed that weren't pressed last frame
  23.  
  24. TextBuf: .res 24    ; Buffer for the current line of text that will go out
  25.  
  26. .code
  27. start:
  28.   jsr init_lcd
  29.  
  30.   jsr UpdateKeys
  31.  
  32. DrawImage:
  33.   lda #<Picture     ; Init pointer to the picture
  34.   sta Pointer+0
  35.   lda #>Picture
  36.   sta Pointer+1
  37.  
  38. DrawImageLoop:      ; Output byte by byte to send the entire picture
  39.   lda (Pointer)
  40.   sta $8001
  41.  
  42.   inc Pointer+0     ; Increment pointer
  43.   bne :+
  44.     inc Pointer+1
  45.   :
  46.  
  47.   lda Pointer+0     ; Stop if the end of the picture is reached
  48.   cmp #<PictureEnd
  49.   bne DrawImageLoop
  50.   lda Pointer+1
  51.   cmp #>PictureEnd
  52.   bne DrawImageLoop
  53.  
  54.  
  55. WaitLoop:           ; Wait for Menu to be pressed
  56.   jsr UpdateKeys
  57.  
  58.   lda keynew
  59.   and #KEY_MENU
  60.   beq :+
  61.     jmp MoveTest
  62.   :
  63.   jmp WaitLoop
  64.  
  65. ; ----------------------------------------
  66.  
  67. MoveTest:           ; Memory explorer
  68.   lda #0            ; Init variables
  69.   sta CursorX
  70.   sta ViewAddress+0
  71.   sta ViewAddress+1
  72.  
  73.   lda #$80
  74.   sta Address
  75.  
  76. Forever:
  77.   jsr StartScreen
  78.  
  79.   ; Display 32 bytes starting at the view address
  80.   ldy #0
  81. ViewLoop:
  82.   lda (ViewAddress),y
  83.   jsr PutHex
  84.   iny
  85.   tya
  86.   and #7
  87.   bne :+
  88.     phy
  89.     jsr PutNewline   ; New line every 8 bytes
  90.     ply
  91.   :
  92.   cpy #$20           ; Stop at 32 bytes
  93.   bne ViewLoop
  94.  
  95.  
  96.  
  97.   ; Write actual menu
  98.   jsr PutNewline
  99.  
  100.   ; Display the current values for address and write/read bytes
  101.   lda Address+0
  102.   jsr PutHex
  103.   lda Address+1
  104.   jsr PutHex
  105.   lda #16
  106.   jsr PutChar
  107.   lda WriteValue
  108.   jsr PutHex
  109.   lda #16
  110.   jsr PutChar
  111.   lda ReadValue
  112.   jsr PutHex
  113.  
  114.   jsr PutNewline
  115.  
  116.   ; ---
  117.   ; Select different digits
  118.   lda keynew
  119.   and #KEY_LEFT
  120.   beq :+
  121.     dec CursorX
  122.   :
  123.   lda keynew
  124.   and #KEY_RIGHT
  125.   beq :+
  126.     inc CursorX
  127.   :
  128.  
  129.   ; Modify current digit
  130.   lda keynew
  131.   and #KEY_DOWN
  132.   beq NotDown
  133.     lda CursorX
  134.     lsr
  135.     bcs DownOnes
  136.   DownTens:
  137.     tax
  138.     lda Address,x
  139.     sub #$10
  140.     sta Address,x
  141.     bra NotDown
  142.   DownOnes:
  143.     tax
  144.     dec Address,x
  145.   NotDown:
  146.  
  147.   lda keynew
  148.   and #KEY_UP
  149.   beq NotUp
  150.     lda CursorX
  151.     lsr
  152.     bcs UpOnes
  153.   UpTens:
  154.     tax
  155.     lda Address,x
  156.     add #$10
  157.     sta Address,x
  158.     bra NotUp
  159.   UpOnes:
  160.     tax
  161.     inc Address,x
  162.     bra NotUp
  163.   NotUp:
  164.  
  165.   ; Menu = read a byte
  166.   lda keynew
  167.   and #KEY_MENU
  168.   beq :+
  169.     lda Address+0
  170.     sta Pointer+1
  171.     lda Address+1
  172.     sta Pointer+0
  173.     ; Read value
  174.     lda (Pointer)
  175.     sta ReadValue
  176.   :
  177.  
  178.   ; Action = write a byte
  179.   lda keynew+1
  180.   and #KEY_ACTION
  181.   beq :+
  182.     lda Address+0
  183.     sta Pointer+1
  184.     lda Address+1
  185.     sta Pointer+0
  186.     ; Write value
  187.     lda WriteValue
  188.     sta (Pointer)
  189.   :
  190.  
  191.   ; Mute = switch the bank in Address into BRR
  192.   lda keynew+1
  193.   and #KEY_MUTE
  194.   beq :+
  195.     lda Address+1
  196.     sta BRRL
  197.     lda Address+0
  198.     sta BRRH
  199.   :
  200.  
  201.   ; Power = move the 32 byte preview to a new spot
  202.   lda keynew
  203.   and #KEY_POWER
  204.   beq :+
  205.     lda Address+1
  206.     sta ViewAddress+0
  207.     lda Address+0
  208.     sta ViewAddress+1
  209.   :
  210.  
  211.  
  212.   ; Stay within the 8 selectable columns
  213.   lda CursorX
  214.   and #7
  215.   sta CursorX
  216.   ; ---
  217.  
  218.   ; Draw cursor
  219.   ldx CursorX
  220.   ldy CursorXOffsets,x
  221.   lda #17
  222.   sta TextBuf,y
  223.   jsr PutNewline
  224.  
  225.   jsr FinishScreen
  226.   jsr UpdateKeys
  227.   jmp Forever
  228.  
  229.  
  230. ; --------------------------------------
  231.  
  232. CursorXOffsets:
  233.   .byt 0, 1, 2, 3, 5, 6, 8, 9
  234.  
  235. ; Start the text screen and init stuff
  236. StartScreen:
  237.   lda #0
  238.   sta DrawX
  239.   sta DrawY
  240.   jmp ClearTextBuf
  241.  
  242. ; Finish the text screen and send out any remaining pixels
  243. FinishScreen:
  244.   ; Draw screen row
  245.   lda TextIdx
  246.   beq :+
  247.     jsr DrawTextRow
  248.   :
  249.  
  250.   ; Send green for as many pixels are left
  251. : lda #$00
  252.   sta $8001
  253.   lda #$f0
  254.   sta $8001
  255.  
  256.   inc DrawX
  257.   lda DrawX
  258.   cmp #WIDTH
  259.   bne :-
  260.   lda #0
  261.   sta DrawX
  262.  
  263.   inc DrawY
  264.   lda DrawY
  265.   cmp #HEIGHT
  266.   bne :-
  267.   rts
  268.  
  269. ; --------------------------------------
  270.  
  271. ; Send current row, move onto the next row
  272. PutNewline:
  273.   jsr DrawTextRow
  274.   jmp ClearTextBuf
  275.  
  276. ; Print the byte in A in hexadecimal
  277. PutHex:
  278.   pha
  279.   lsr
  280.   lsr
  281.   lsr
  282.   lsr
  283.   jsr PutChar
  284.   pla
  285.   and #15
  286. ; Print one character
  287. PutChar:
  288.   phx
  289.   ldx TextIdx
  290.   sta TextBuf,x
  291.   inc TextIdx
  292.   plx
  293.   rts
  294.  
  295. ; Clear the text buffer
  296. ClearTextBuf:
  297.   ldx #23
  298.   lda #0
  299.   sta TextIdx
  300.   lda #16
  301. : sta TextBuf,x
  302.   dex
  303.   bpl :-
  304.   rts
  305.  
  306. ; Draw a row of text
  307. DrawTextRow:
  308.   jsr DrawTextRow1
  309.   jsr DrawTextRow2
  310.   jsr DrawTextRow2
  311.   jsr DrawTextRow3
  312.   jsr DrawTextRow4
  313.   jsr DrawTextRow4
  314.   jsr DrawTextRow5
  315.  
  316.   ; Add a row of white as a spacer
  317.   ldx #WIDTH
  318. : jsr WhitePixel
  319.   dex
  320.   bne :-
  321.   inc DrawY
  322.   rts
  323.  
  324.  
  325. DrawTextRow1:
  326.   ldx #0
  327. : ldy TextBuf,x
  328.   lda Font1,y
  329.   jsr DrawCharRow
  330.   inx
  331.   cpx #24
  332.   bne :-
  333.   bra DrawTextRowCommon
  334.  
  335. DrawTextRow2:
  336.   ldx #0
  337. : ldy TextBuf,x
  338.   lda Font2,y
  339.   jsr DrawCharRow
  340.   inx
  341.   cpx #24
  342.   bne :-
  343.   bra DrawTextRowCommon
  344.  
  345. DrawTextRow3:
  346.   ldx #0
  347. : ldy TextBuf,x
  348.   lda Font3,y
  349.   jsr DrawCharRow
  350.   inx
  351.   cpx #24
  352.   bne :-
  353.   bra DrawTextRowCommon
  354.  
  355. DrawTextRow4:
  356.   ldx #0
  357. : ldy TextBuf,x
  358.   lda Font4,y
  359.   jsr DrawCharRow
  360.   inx
  361.   cpx #24
  362.   bne :-
  363.   bra DrawTextRowCommon
  364.  
  365. DrawTextRow5:
  366.   ldx #0
  367. : ldy TextBuf,x
  368.   lda Font5,y
  369.   jsr DrawCharRow
  370.   inx
  371.   cpx #24
  372.   bne :-
  373.   bra DrawTextRowCommon
  374.  
  375. DrawTextRowCommon:
  376.   ; Round out the 96 pixels of text with 2 more
  377.   jsr WhitePixel
  378.   jsr WhitePixel
  379.  
  380.   inc DrawY
  381.   rts
  382.  
  383.  
  384. DrawCharRow:         ; Draw a whole character row
  385.   jsr DrawCharRowOne
  386.   jsr DrawCharRowOne
  387.   jsr DrawCharRowOne
  388. DrawCharRowOne:      ; Draw one pixel from the row
  389.   and #%1111
  390.   asl
  391.   cmp #%10000
  392.   bcs BlackPixel
  393.  
  394. WhitePixel:
  395.   pha
  396.   lda #$0f
  397.   sta $8001
  398.   lda #$ff
  399.   sta $8001
  400.   pla
  401.   rts
  402. BlackPixel:
  403.   pha
  404.   lda #$00
  405.   sta $8001
  406.   sta $8001
  407.   pla
  408.   rts
  409.  
  410. ; --------------------------------------
  411.  
  412. UpdateKeys:
  413. ; Set 1
  414.   lda keydown+0
  415.   sta keylast+0
  416.   lda PA
  417.   eor #255 ; Make 1=pressed, 0=unpressed
  418.   sta keydown+0
  419.  
  420.   lda keylast+0
  421.   eor #255
  422.   and keydown+0
  423.   sta keynew+0
  424. ; Set 2
  425.   lda keydown+1
  426.   sta keylast+1
  427.   lda PB
  428.   eor #255 ; Make 1=pressed, 0=unpressed
  429.   sta keydown+1
  430.  
  431.   lda keylast+1
  432.   eor #255
  433.   and keydown+1
  434.   sta keynew+1
  435.   rts
  436.    
  437. init_lcd:
  438.   lda #$a7 ;colors
  439.   sta $8000
  440.  
  441.   lda #$5c
  442.   sta $8000
  443.   rts
  444.  
  445.  
  446. Picture:
  447.   .incbin "picture.bin"
  448. PictureEnd:
  449.  
  450. Font1:
  451.   .byt %111 ;0
  452.   .byt %010 ;1
  453.   .byt %010 ;2
  454.   .byt %110 ;3
  455.   .byt %101 ;4
  456.   .byt %111 ;5
  457.   .byt %011 ;6
  458.   .byt %111 ;7
  459.   .byt %010 ;8
  460.   .byt %111 ;9
  461.   .byt %010 ;A
  462.   .byt %110 ;B
  463.   .byt %011 ;C
  464.   .byt %110 ;D
  465.   .byt %111 ;E
  466.   .byt %111 ;F
  467.   .byt %000 ;
  468.   .byt %111 ;
  469. Font2:
  470.   .byt %101 ;0
  471.   .byt %110 ;1
  472.   .byt %101 ;2
  473.   .byt %001 ;3
  474.   .byt %101 ;4
  475.   .byt %100 ;5
  476.   .byt %100 ;6
  477.   .byt %001 ;7
  478.   .byt %101 ;8
  479.   .byt %101 ;9
  480.   .byt %101 ;A
  481.   .byt %101 ;B
  482.   .byt %100 ;C
  483.   .byt %101 ;D
  484.   .byt %100 ;E
  485.   .byt %100 ;F
  486.   .byt %000 ;
  487.   .byt %111 ;
  488. Font3:
  489.   .byt %101 ;0
  490.   .byt %010 ;1
  491.   .byt %001 ;2
  492.   .byt %110 ;3
  493.   .byt %111 ;4
  494.   .byt %111 ;5
  495.   .byt %111 ;6
  496.   .byt %010 ;7
  497.   .byt %010 ;8
  498.   .byt %111 ;9
  499.   .byt %111 ;A
  500.   .byt %110 ;B
  501.   .byt %100 ;C
  502.   .byt %101 ;D
  503.   .byt %111 ;E
  504.   .byt %111 ;F
  505.   .byt %000 ;
  506.   .byt %111 ;
  507. Font4:
  508.   .byt %101 ;0
  509.   .byt %010 ;1
  510.   .byt %010 ;2
  511.   .byt %001 ;3
  512.   .byt %001 ;4
  513.   .byt %001 ;5
  514.   .byt %101 ;6
  515.   .byt %010 ;7
  516.   .byt %101 ;8
  517.   .byt %001 ;9
  518.   .byt %101 ;A
  519.   .byt %101 ;B
  520.   .byt %100 ;C
  521.   .byt %101 ;D
  522.   .byt %100 ;E
  523.   .byt %100 ;F
  524.   .byt %000 ;
  525.   .byt %111 ;
  526. Font5:
  527.   .byt %111 ;0
  528.   .byt %111 ;1
  529.   .byt %111 ;2
  530.   .byt %110 ;3
  531.   .byt %001 ;4
  532.   .byt %110 ;5
  533.   .byt %111 ;6
  534.   .byt %100 ;7
  535.   .byt %010 ;8
  536.   .byt %110 ;9
  537.   .byt %101 ;A
  538.   .byt %110 ;B
  539.   .byt %011 ;C
  540.   .byt %110 ;D
  541.   .byt %111 ;E
  542.   .byt %100 ;F
  543.   .byt %000 ;
  544.   .byt %111 ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement