Кодинг для Спектрум и 8бит

Информация о пользователе

Привет, Гость! Войдите или зарегистрируйтесь.


Вы здесь » Кодинг для Спектрум и 8бит » 6502 » 6502 tricks


6502 tricks

Сообщений 1 страница 6 из 6

1

SWN(swap nibble)

Код:
;David Galloway made this suggestion on the facebook 6502 Programming group, for swapping nybbles. $36 becomes $63, $A1 becomes $1A, etc.. It takes only 8 bytes and 12 clock cycles, and no variables, no stack usage, no look-up table, no X or Y usage. It uses only the accumulator and status register.
        ASL  A
        ADC  #$80
        ROL  A
        ASL  A
        ADC  #$80
        ROL  A


Задержка

Код:
Need a slick delay?  Take this one from Bruce Clark.  The delay is 9*(256*A+Y)+8 cycles (plus 12 more for JSR & RTS if you make it a subroutine).  This assumes that the BCS does not cross a page boundary.

loop:   CPY  #1
        DEY
        SBC  #0
        BCS  loop

2

Арифметическое деление на 2

Код:
;http://web.archive.org/web/20130212045246/http://mycorner.no-ip.org:80/6502/shorts/index.html
	CMP	#$80    ; copy the sign bit to the carry bit    
	ROR	A    ; effectively perform a true ASR	

3

уменьшение 16бит

Код:
    LDA LO
    BNE :CONT
    DEC HI
	:CONT	DEC LO

4

Циклическое вращение

Код:
ASL A
ADC #0

5

Определение PC

Код:
      ;  What is my address?
      jsr Next_Inst
      Next_Inst   pla
      clc
      adc #$01
      sta PCL
      pla
      adc #$00
      sta PCH
      ;
      ; The address of Next_Inst is in PCH, PCL
      ;

6

http://codebase64.org/doku.php?id=base: … ii_routine

Код:
Tiny .A to ASCII routine
From somebody in comp.sys.cbm, don't remember who nor if I tweaked it further to get this version. The thread was probably “Converting An 8-bit Number Into A String”, but I couldn't find it in Google.

Converts .A to 3 ASCII/PETSCII digits: .Y = hundreds, .X = tens, .A = ones

  ldy #$2f
  ldx #$3a
  sec
- iny
  sbc #100
  bcs -
- dex
  adc #10
  bmi -
  adc #$2f
  rts

Вы здесь » Кодинг для Спектрум и 8бит » 6502 » 6502 tricks