rom.asm (2163B)
1 // 2 // Fibonacci numbers 3 // 4 5 #define DATA_PTR_0 $15 6 #define DATA_PTR_1 $16 7 #define DATA_PTR_2 $17 8 .set_address $80 9 // Set initial values 10 LDA #$00 11 STA $00 12 LDA #$01 13 STA $01 14 initialize_data_pointers: 15 LDA #$00 16 STA DATA_PTR_0 17 LDA #$01 18 STA DATA_PTR_1 19 LDA #$02 20 STA DATA_PTR_2 21 loop: 22 // Compute next value 23 LDA (DATA_PTR_0) 24 ADD (DATA_PTR_1) 25 STA (DATA_PTR_2) 26 // Increment pointers 27 // DATA_PTR_0 28 LDA DATA_PTR_0 29 // Check if we have reached 30 // the end of visible RAM 31 ADD #$EC // (-20 % 255) + 1 32 JNZ :DATA_PTR_0_in_range 33 LDA #$EB // Set accumulator to #$EB + #$16 = 00 34 DATA_PTR_0_in_range: 35 ADD #$15 // Increment accumulator by #$EC + #$15 - 1 = 1 36 STA DATA_PTR_0 37 // DATA_PTR_1 38 LDA DATA_PTR_1 39 // Check if we have reached 40 // the end of visible RAM 41 ADD #$EC // (-20 % 255) + 1 42 JNZ :DATA_PTR_1_in_range 43 LDA #$EB // Set accumulator to #$EB + #$16 = 00 44 DATA_PTR_1_in_range: 45 ADD #$15 // Increment accumulator by #$EC + #$15 - 1 = 1 46 STA DATA_PTR_1 47 // DATA_PTR_2 48 LDA DATA_PTR_2 49 // Check if we have reached 50 // the end of visible RAM 51 ADD #$EC // (-20 % 255) + 1 52 JNZ :DATA_PTR_2_in_range 53 LDA #$EB // Set accumulator to #$EB + #$16 = 00 54 DATA_PTR_2_in_range: 55 ADD #$15 // Increment accumulator by #$EC + #$15 - 1 = 1 56 STA DATA_PTR_2 57 JMP :loop 58 59 // 60 // Load RAM from serial line 61 // 62 63 #define UART_STATUS $FF 64 #define UART_DATA $FE 65 #define DATA_PTR $7F 66 #define MASK_RECV_BUFFER_FULL $FE 67 #define MASK_TX_BUSY $FF 68 start: 69 // Start writing serial data at begin of RAM 70 LDA #$00 71 STA DATA_PTR 72 STA UART_STATUS // Clear recv_buffer_full; ready to receive next byte. 73 receive_loop: 74 LDA UART_STATUS 75 AND #$02 76 JZE :receive_loop 77 // Byte received. 78 // Store it in RAM and advance data pointer. 79 LDA UART_DATA 80 STA (DATA_PTR) 81 LDA DATA_PTR 82 INC 83 STA DATA_PTR 84 STA UART_STATUS // Clear recv_buffer_full 85 // Confirm reception of byte 86 LDA #$AA 87 STA UART_DATA 88 // Wait until byte sent 89 send_loop: 90 LDA UART_STATUS 91 AND #$01 92 JNZ :send_loop 93 JMP :receive_loop