Update: All needed files for this tutorial can be found in the GitHub repo linked in the bottom of this page.
We are not going to introduce many new things in this tutorial, just use what you know to create more than one interrupt. Interrupts can be used to split you screen into different sections.
An important note is that these “interrupts” is your bridge to how it will be done when you get to a more advanced level (will be covered in a later part) and is intended for beginners. These will get you going, but know that there is a better and more correct way to do interrupts. In how I teach, I find it easier to start this way and then move to the correct way when the basic understanding is in place.
Anyways, say you want one part of your screen to render an image, and then once the image is rendered, you want to render some text. That means that you must set up your screen to support both graphic mode and text mode. This can be done with interrupts!
I’m going to create a program that splits the screen into two, where the first part got a purple color and the second part got a green color. We split the screen on every refresh using two interrupts.
The first interrupt does some logic before changing the IRQ vector to point to another “IRQ function” before returning to the main loop. The other interrupt does some logic, triggers another raster interrupt, changes the IRQ vector back to the original and returns to the main loop.
Not much is changed since the previous tutorial. We start with the exact same logic until the main loop starts to run:
processor 6502
org $0810
; initiate music
lda #$00
tax
tay
jsr $1000
;clear screen
jsr $e544
; disable interrupts
sei
lda #$7f
sta $dc0d
sta $dd0d
lda #$01
sta $d01a
; set text mode
lda #$1b
ldx #$08
ldy #$14
sta $d011
stx $d016
sty $d018
; init irq
lda #<irq
ldx #>irq
sta $0314
stx $0315
; create rater interrupt
ldy #$00
sty $d012
; clear interrupts and ACK irq
lda $dc0d
lda $dd0d
asl $d019
cli
loop: jmp loop
In the first irq, we set the color of the border and mainscreen, updates the music..
irq: lda #$04
sta $d020
sta $d021
jsr $1006
..and then use the same logic as earlier to set the IRQ vector to point to irq2.
lda #<irq2
ldx #>irq2
sta $0314
stx $0315
We set the next raster interrupt at line 160:
ldy #160
sty $d012
asl $d019
jmp $ea81
The code for the 2nd interrupt is very similar to the first one. We set the color of the border and the screen, and then set the IRQ-vector to point on irq.
irq2:
lda #$05
sta $d020
sta $d021
lda #<irq
ldx #>irq
sta $0314
stx $0315
ldy #$00
sty $d012
asl $d019
jmp $ea81
Finally, we set the music at location $1000-7e:
org $1000-$7e
INCBIN “music.sid”
As I said, nothing new here really. Interrups are really handy when it comes to splitting the screen and timing. One thing to remember is that these interrups are not stable, so you might see some jittering or artifacts on the screen. It’s all about timing. We are going to see how to create stable interrupts in a later tutorial.
Note: You are not limited to only have two interrupts. Feel free to play around a bit, make some lines and so on.
An excerise for you:
Try to see if you can get the position of the split to move up and down. It might not be as easy as you thing, but you should be able to do this by now!
Listing 10.1 – More than one interrupt
processor 6502
org $0810
; initiate music
lda #$00
tax
tay
jsr $1000
;clear screen
jsr $e544
; disable interrupts
sei
lda #$7f
sta $dc0d
sta $dd0d
lda #$01
sta $d01a
; set text mode
lda #$1b
ldx #$08
ldy #$14
sta $d011
stx $d016
sty $d018
; init irq
lda #<irq
ldx #>irq
sta $0314
stx $0315
; create rater interrupt at line 0
ldy #$00
sty $d012
; clear interrupts and ACK irq
lda $dc0d
lda $dd0d
asl $d019
cli
loop: jmp loop
irq: lda #$04
sta $d020
sta $d021
jsr $1006
lda #<irq2
ldx #>irq2
sta $0314
stx $0315
; Create raster interrupt at line 160
ldy #160
sty $d012
asl $d019
jmp $ea81
irq2:
lda #$05
sta $d020
sta $d021
lda #<irq
ldx #>irq
sta $0314
stx $0315
ldy #$00
sty $d012
asl $d019
jmp $ea81
org $1000-$7e
INCBIN “music.sid”
Downloads
Download the source from GitHub:
https://github.com/petriw/Commodore64Programming/tree/master/10-MultipleInterrupts
Pingback: GeekBeat.TV – Tech Nostalgia with New Commodore 64 GB166 | Taking care of your pet
Pingback: Windows Client Developer Roundup 068 for 5/9/2011 - Pete Brown's 10rem.net
took me FOREVER to get this right, and when I finally did, I didn’t understand it fully the first time. Well, ok, hold up – I mean _STABLE_ double raster interrupts. Not just, you know, double interrupts. That I had. It was the emphasis on timing, and the whole “yes you can have the code right but you still have to trigger it properly or it doens’t work” stuff that was driving me nuts.
Have it down now, but, it’s a total and complete _PAIN_ to do. Luckily Vice has cycle counting in it’s debugger. (Vice’s debugger is fairly crap otherwise (: But the cycle counting rules.)
Love these tutorials, thanks for finally getting me into ML after 25 years of wishing I could learn it! I hope you keep going, it’s very inspirational.
Pingback: Books, Papers and Links – Computer Graphics « T客网 ︱ Techpot
VERY GOOD!!!
Where is the Commodore 64 Programming #11?
Great Stuff d00d. It would be great if you could write a little scroller too.
Thank you so much Digitalerr0r.
After perhaps a hundred of hours I now can do anything I want. ASM is hard but the only sucky part is the information.
It’s amazing how things are simpler when you use the multiple IRQ, but it’s good to test every possibilities without first.
I’ve being a bit lost, but with your web site, dustlayer and “an introduction to programming by puterman” (google cache) and this last very major tuto on multiple interupts (once you know the basics, use this because it won’t be smooth and sync otherwise) everyone should be happy.
Every tutos have many typos and errors, sometime I was crazy.. It’s behind me now.
Also, now I really have an idea why Basic is slow and why the amazing things it can achieve can’t be sync (and will never)
Thank you very much, very good tutos,I discovered lots of things completely unknown to me.
I bought my first c64 in 1986…
Soon the number 11?
Sorry for my bad english
Bye
sty $d014 is useless here, it’s lightpen y position and it’s readonly
did you mean $d018?
Hello there, I do believe your blog may be having web
browser compatibility issues. When I take a look at your site in Safari, it looks fine however when opening in Internet Explorer, it has some overlapping issues.
I just wanted to give you a quick heads up! Other than that, fantastic website!
Have you ever thought about creating an e-book or guest authoring on other websites?
I have a blog based upon on the same subjects you discuss
and would really like to have you share some stories/information. I
know my visitors would value your work. If you are even remotely interested, feel free to shoot me an e mail.
Hello, this weekend is pleasant designed for me, since this time i am reading this great educational paragraph here
at my home.
Will we ever see more of these great commodore tutorials?
Bạn đang có kế hoạch xây phòng trọ Về phía
nhà thầu với kinh nghiệm làm nhà lâu năm
trong nghề về tư vấn thiết kế thi công xây dựng họ sẽ làm bạn hài lòng
về sự lựa chọn của bạn.Với kinh nghiệm đó họ có thể dễ
dàng thu xếp mọi thứ… có niềm tin vào uy tín của chúng
tôi Chọn lựa vật tư và phối hợp nội thất:
Tưởng chừng như việc này khá đơn giản và ai cũng có thể làm được nhưng
không phải vậy. Đối với màu sơn, gạch lát và các thiết bị trong nhà, thoạt
nhìn thì sẽ rất đẹp nhưng khi phối
vào nhà chúng trở nên đối nghịch nhau tạo ra sự bất hòa trong ngôi nhà…
Dịch vụ xây dựng nhà trọn gói giá rẻ Với kinh nghiệm lâu năm trong xây dựng và đội ngũ kiến trúc sư giỏi họ sẽ chọn và phối hợp hài hòa giữa màu sơn, gạch lát nền, nội thất… tạo nên sự tinh
tế và thoải mái nhất cho ngôi nhà của bạn. Hưng Yên
Bạn không phải mất nhiều thời gian để trực tiếp giám sát công trình.
Yên tâm làm việc trong thời gian thi công.
Căn cứ vào các điều khoản đã thõa thuận trong hợp đồng để quản lý việc xây dựng với nhà thầu…
Đơn giáTừ 4.500.000 -> 6.500.000đ/m2 sàn XD( Giá cụ
thể tùy theo qui mô công trình, chủng loại vật tư… )
Grupo LaBE presta servicios que abarcan las siguientes áreas: Servicios Legales, Consultoría
y Asesoría Fiscal, dirigidos a grandes empresas, pymes y autónomos.
El principal objetivo del Grupo LaBE es prestar servicios que aporten valor a su negocio.
Esta forma de trabajo nos ha hecho acreedores de la confianza
de todos y cada uno de nuestros clientes.
Como resultado de las sinergias de nuestros distintos departamentos ofrecemos soluciones eficaces para
cada uno de nuestros clientes. Grupo LaBE cuenta con profesionales altamente
cualificados y con experiencia internacional.
So you, as the restorer, have to set realistic goals as to exactly what parts of the car you are going to restore to
their original states and what parts of the car you are willing to
restore “as close as possible” to their original
states. Be smart and savvy when negotiating the
interest rate for new cars and don’t just sign on the bottom line.
00 per gallon, depending on market prices, but that is a good benchmark.
What’s up, I want to subscribe for this webpage to obtain latest updates, so where can i do it
please assist.
bạn dự đinh xây nhà trọ Công ty trang trí nội thất chuyên thiết kế nội thất công ty, nội thất nhà
phố, nôi thất căn hộ chung cư … mau thu hồi vốn khi
đầu tư nhà trọ cửa hàng trang trí nội thất đồ gỗ.
phòng khách, phòng ngủ phòng ăn, nhà bếp, phòng tắm phòng trẻ em.
siêu thị bàn ghế sofa, kệ tủ tivi, kệ tủ bếp, giường ngủ…
Dịch vụ xây dựng nhà trọn gói giá rẻ Trang trí nội thất là một ngành đòi hỏi các đội ngũ
kiến trúc sư và chuyên gia họa sỹ phối kết hợp ăn ý với nhau.
Ngành trang trí nội thất ở Việt Nam chúng ta….
Bình Thuận Chuyên trang trí nội thất nhà, gia
đình, văn phòng, nội thất căn hộ chung cư đẹp.Trang trí nội thất hiện đại,
nội thất căn hộ cao cấp phù hợp với nhà bạn.… Đơn giá xây nhà trọn gói
từ 3.200.000 đến 5.000.000đ / m2 xây dựng hoàn công Đơn giá trên phụ
thuộc vào chất liêu thi công
xây phòng trọ cho thuê
Have you ever considered creating an ebook or guest authoring on other websites?
I have a blog centered on the same subjects you discuss and would love to have you share some
stories/information. I know my subscribers would enjoy your
work. If you’re even remotely interested, feel free to send me an email.
bạn muốn chúng tôi tư vấn xây nhà trọ Và quý khách đang cân nhắc tìm một công ty xây dựng uy tín với chuyên môn cao để tân trang lại ngôi nhà, Xây dựng Hòa Hưng chính là sự lựa chọn số 1 cho khách hàng với nhiều dịch vụ ưu đãi.…
Chúng tôi sẽ tư vấn cho bạn giúp bạn xây nhà đẹp
Theo kiến trúc sư Công ty Xây dựng Hòa Hưng cho biết,
thông thường đơn giá xây nhà trọn gói
sẽ bao gồm nhiều hạng mục, nhưng chủ yếu phụ
thuộc vào 3 yếu tố sau…. công ty xây dựng hồ hà Đơn giá thi công được áp dụng cho
quy trình thi công bao gồm chi phí giám sát và quản lý công trình, cũng như tất
cả các khoản bảo hiểm của nhà thầu và bên thứ
ba….. Tây Ninh Có rất nhiều lý do để quý khách làm mới lại căn hộ của mình như:
ngôi nhà quá cũ, các hạng mục xuống cấp, chuyển nhà, mua nhà mới,.… công ty thi công xây dựng
xay phong tro gia re
bạn dự đinh xây nhà trọ Việc tiếp theo chính là lập dự toán chi phí xây dựng nhà ở để xác định nguồn vốn tài chính mà gia chủ mang đi đầu
tư..… Chúng tôi sẽ hổ trợ giúp bạn xây nhà theo tiêu chuẩn xây dựng nhà ở của bộ xây dựng
Dịch vụ xây dựng Toàn Cầu Bước thứ 3 cũng là
bước cuối cùng trong trình tự xây nhà là thi công và hoàn công.
Hầu hết việc này được giao cho đơn vị nhà thầu hoàn tất……
Cần giờ những lời nói xuôi tai và chắc như đinh
đóng cột nhưng sau đó là khiến bạn mất thời gian và tiền bạc do thiếu tính minh bạch và rõ ràng ngay từ lúc ký kết.,.… Chung
tôi sẽ giúp bạn tiết kiệm chi phí nhất
Chúng tôi xin gới thiệu chúng tôi chuyên xây
nhà Và quý khách đang cân nhắc tìm một công ty xây dựng uy
tín với chuyên môn cao để tân trang lại ngôi nhà,
Xây dựng Hòa Hưng chính là sự lựa chọn số 1 cho khách hàng
với nhiều dịch vụ ưu đãi.… Chúng tôi sẽ
tư vấn cho bạn giúp bạn xây nhà đẹp Theo kiến trúc sư
Công ty Xây dựng Hòa Hưng cho biết, thông thường đơn giá
xây nhà trọn gói sẽ bao gồm nhiều hạng mục, nhưng chủ yếu phụ thuộc vào 3 yếu tố sau….
công ty xây dưng nhà giá rẻ Đơn giá thi công được áp dụng cho quy trình thi công bao
gồm chi phí giám sát và quản lý công trình, cũng như tất cả
các khoản bảo hiểm của nhà thầu và bên thứ ba…..
Tại các tỉnh trong cả nước Có rất nhiều lý do để quý khách
làm mới lại căn hộ của mình như: ngôi nhà quá cũ, các hạng mục xuống
cấp, chuyển nhà, mua nhà mới,.… công xây dựng nhà
giá xây nhà trọ
JV Limpiezas realiza tareas de desinfección, desratización y desinsectación. https://hamishlowman1.wordpress.com/2016/11/14/limpiezas-edelweis/
Grerat blog right here! Additionally your website loads up very fast!
What wweb ost are you the use of? Can I amm getting your affiliate
hyperlink to your host? I desire my website loaded up as quickly
as yours lol.
Ban đang muốn đầu tư nhà trọ Công ty trang trí nội thất chuyên thiết kế
nội thất công ty, nội thất nhà phố, nôi
thất căn hộ chung cư … chúng tôi tư vấn cho bạn cách tốt nhất
cửa hàng trang trí nội thất đồ gỗ.
phòng khách, phòng ngủ phòng ăn, nhà bếp, phòng tắm phòng trẻ
em. siêu thị bàn ghế sofa, kệ tủ
tivi, kệ tủ bếp, giường ngủ… Công ty xây dựng nhà trọn gói Hữu Thắng Trang trí nội thất là
một ngành đòi hỏi các đội ngũ kiến trúc
sư và chuyên gia họa sỹ phối kết hợp ăn ý với nhau.
Ngành trang trí nội thất ở Việt Nam chúng ta….
Sóc trăng Chuyên trang trí nội thất nhà, gia
đình, văn phòng, nội thất căn hộ chung cư đẹp.Trang trí nội thất hiện đại, nội thất căn hộ cao cấp phù hợp với nhà bạn.… Chúng tôi khảo
sát và báo giá họp lý cho quý gia chủ
xây nhà trọ giá rẻ
Apart from full-on surgery, men are also investing in less invasive cosmetic operations
to look better. If you run a blog or fan site that focusses on MMOs, and would like to
join our program, send a message to Michael Hartman, the ME of the Bright Hub MMO channel.
Pamela Anderson may be seen as a synonym in the dictionary for breast implants.
Great information. Lucky me I ran across your site by accident (stumbleupon).
I’ve book-marked it for later!
Isso é carissimo, se compensa solitário Antonio que é utilizador da maquina pode dizer.
If you wish for to get a great deal from this paragraph then you have to apply these strategies to your won web site.