Somewhat eclipsed by Notch's project is the 6502 emulator now available for Minecraft as part of Prerelease 5 of the mod RedPower 2 by Eloraam.Įloraam calls it the 65EL02, because "it supports all the 6502, 65C02, and part of the 65C816 instruction set" as well as "a set of completely new instructions and two addressing modes."
My 6502 manual says: "Above all, remember that comparing is done with BCS and BCC ( not BPL or BMI).Notch's new game 0x10c and its virtual 16-bit computer, the DCPU-16, have made news recently. Label lda Lo Load from a zero page address Lo equ $90 The 16-bit bin is stored at zero page address $90 Then you branch based on the Z from the ora and the C from the (last) sbc. You can add an ora instruction to see if the resulting word has become negative. The X register now contains how many times 10000 fitted in the original number. Sec Because SBC subtracts the complement of Cīcs Label Result GE 0 (greater or equal)
The low byte is at $90, the high byte is at $91 (little endian). Next example subtracts 10000 ($2710) from the unsigned word stored at zero page address $90.
The problem is how to detect the 'below 0' condition as said in the post Do. In the first iteration I sub 10000 each cycle until the result is 'below 0', then I restore the previous value and continue with the remainder. The bin value could be >$8000, so it is 'negative' but this does not matter.
This code is part of a Bin to Ascii conversion, made by power of ten subtraction. Only you can decide which one is correct! The 1st one continues on 0, the 2nd one stops on 0. Loop through a 16 bit subtraction until the result is negativeĭo you see that these descriptions contradict each other? If your emulator leaves the carry unset in that situation, your emulator has a bug.
clcĪnd here is the Visual 6502 trace cycle ab db rw Fetch pc a x y s pĢ 0001 a9 1 LDA # 0001 aa 00 00 fd nv‑BdIZcĤ 0003 e9 1 SBC # 0003 90 00 00 fd Nv‑BdIzc Here is a simplified bit of code that subtracts $0a from $90 with the carry clear. The hex for 2000 is $07d0.įollowing the latest edit to the question. If you load 0 into a zero page location and 20 decimal into its successor, you've actually loaded 20 * 256 = 5120. If you have 2000 (decimal), then to load it into two locations, you need to convert it to hex before you slice it into two bytes. There is another problem with your code, by the way. I have run this in an online 6502 emulation and the carry was set by the time it got to the final sta V1. If it is not, then the most likely cause is a bug in your emulator. With the values used in the code, the carry will be cleared after the first subtraction and will be set again after the second. Generally, a sequence like this (I've slightly amended the code in your question to make it more self contained) V1 equ $91
V1=$1 and V2=$0A I will have a result < 0, which is my goal to stop iterations. I can not test the result with BCS (to jump to label) nor BMI since V2 is negative. carry is cleared result ($85FF) is still negative).the second sub ($90-$0A-1 (not borrow)) results in V2=$85.Let me try to follow the logic, firstly with the original values as in code. I did not find in the aswers a real solution. The BPL in not valid if V1 is 'negative' (>$80). The BCS is not valid if the V2 subtraction clears the carry. Now, the problem is to identify which branch to select or to find a different solution. "Branch" to Label if result is >0, otherwise exit I have to loop through a 16 bit subtraction until the result is negative: quite simple, no? Here is an example: V1 equ $90 During testing I discovered something wrong, surely due to an error in my implementation. I have recovered an old 6502 emulator I did years ago to implement some new features.