While attempting to write a game in 256 bytes I needed a routine to draw lines, but Bresenham's line algorithm weighs in at approx ~120 bytes. The only suitable alternative I'm aware of is recursive divide and conquer: divide a line into two smaller lines and call the draw routine with each in turn:
/* Draw a line from (ax,ay) to (bx,by) */
int draw ( ax, ay, bx, by )
{
int midx, midy;
midx = ( ax+bx ) / 2;
midy = ( ay+by ) / 2;
if ( midx != ax && midy != ay )
{
draw( midx, midy, ax, ay );
draw( bx, by, midx, midy );
plot( midx, midy );
}
}
This is significantly smaller thank Bresenham's, 32 byte of Z80. However, there are a couple of compromises: it's slower and the lines aren't perfect because the rounding errors accumulate.
; draw lines using recursive divide and conquer
; from de = end1 (d = x-axis, e = y-axis)
; to hl = end2 (h = x-axis, l = y-axis)
DRAW:
call PLOT
push hl
; calculate hl = centre pixel
ld a,l
add a,e
rra
ld l,a
ld a,h
add a,d
rra
ld h,a
; if de (end1) = hl (centre) then we're done
or a
sbc hl,de
jr z,EXIT
add hl,de
ex de,hl
call DRAW ; de = centre, hl = end1
ex (sp),hl
ex de,hl
call DRAW ; de = end2, hl = centre
ex de,hl
pop de
ret
EXIT:
pop hl
ret
; ---------------------------
; plot d = x-axis, e = y-axis
PLOT:
push hl
ld a,d
and 7
ld b,a
inc b
ld a,e
rra
scf
rra
or a
rra
ld l,a
xor e
and 248
xor e
ld h,a
ld a,l
xor d
and 7
xor d
rrca
rrca
rrca
ld l,a
ld a,1
PLOTBIT:
rrca
djnz PLOTBIT
or (hl)
ld (hl),a
pop hl
ret
Alternatively the de(end1) = hl(centre)
test can be replaced with a recursion depth count to create an even slower 28 byte routine:
; draw lines using recursive divide and conquer
; from de = end1 (d = x-axis, e = y-axis)
; to hl = end2 (h = x-axis, l = y-axis)
DRAW:
ld c,8
DRAW2:
dec c
jr z,EXIT
push de
; calculate de = centre pixel
ld a,l
add a,e
rra
ld e,a
ld a,h
add a,d
rra
ld d,a
call DRAW2 ; de = centre, hl = end1
ex (sp),hl
call DRAW2 ; de = centre, hl = end2
call PLOT
ex de,hl
pop hl
EXIT:
inc c
ret

Fantastic work! Thanks for sharing, if I had a ZX Spectrum, I'd definitely try this out. :)
ReplyDeleteHi John,
ReplyDeleteDo you know where I can find an implementation of the Bresenham line drawing in Z80? I'm not too bothered about the size of the code, I'm just trying to understand how to do it correctly, :)
That PLOT: routine pretty much sums up why I never managed to learn machine code. It's easy to learn what all the instructions do on their own, but when they get put together, they just become a jumble.
ReplyDeleteYou set the last three bits of the X co-ordinate and add one to it, for some reason. And then it gets really weird when you move on to the Y coordinate. I think "rra, scf, rra, or a, rra" might mean something like "divide by 8 then add 64" but when you Xor it with the number you first thought of, then And it with something else, and Xor it with the number you first thought of once again, my brain just turns to mush.
How does anyone follow all that, let alone understand it enough to write it?
Ah, I've just worked out that setting the last 3 bits and adding one is probably like rounding the X co-ordinate up to the next multiple of 8. Maybe that's something to do with the X axis having 8 pixels to each screen byte? Am I getting warmer?
DeleteThough if you're trying to use as few bytes as possible (to pack as much game as possible into a 16K Spectrum?) a simple CALL to ROM would only be 3 bytes. That's a lot less than all this "Round up and divide by the number you first thought of" stuff.
This blog shows that you have a great career as a content writer
ReplyDeleteHadoop Training in Chennai
Big Data Training in Chennai
Hadoop Course in Chennai
best big data training in chennai
The Post which you wrote is full of informative and vital blogs. I like it very much. Thank you for your work.
ReplyDeletePHP Training in Chennai
PHP Course in Chennai
Selenium Training in Chennai
Software Testing Training in Chennai
Python Training in Chennai
PHP Training in Annanagar
PHP Training in Velachery
i adore perusing this article so beautiful!!great work! learn more
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYou there, this is really good post here. Thanks for taking the time to post such valuable information. antimalware service executable high disk usage win 10
ReplyDeleteThis is extremely fascinating substance! I have completely delighted in perusing your focuses and have arrive at the conclusion that you are right about a number of them. https://freegrapi.com/
ReplyDeleteHi,
ReplyDeleteGood job & thank you very much for the new information, i learned something new. Very well written. It was sooo good to read and usefull to improve knowledge. Who want to learn this information most helpful. One who wanted to learn this technology IT employees will always suggest you take data science course training bangalore. Because data science course in pune is one of the best that one can do while choosing the course.
I Got Job in my dream company with decent 12 Lacks Per Annum salary, I have learned this world most demanding course out there in the current IT Market from the Hkbk group of institutions experts who helped me a lot to achieve my dreams comes true. Really worth trying
ReplyDeleteGood
ReplyDeletefreein
planttrainingcourseforECEstudents
intern
ship-in-chennai-for-bsc
inpla
nt-training-for-automobile-engineering-students
freein
planttrainingfor-ECEstudents-in-chennai
intern
ship-for-cse-students-in-bsnl
applic
ation-for-industrial-training
Keep posting
ReplyDeleteinterview-questions/aptitude/permutation-and-combination/how-many-groups-of-6-persons-can-be-formed
tutorials/oracle/oracle-delete
technology/chrome-flags-complete-guide-enhance-browsing-experience/
interview-questions/aptitude/time-and-work/a-alone-can-do-1-4-of-the-work-in-2-days
interview-questions/programming/recursion-and-iteration/integer-a-40-b-35-c-20-d-10-comment-about-the-output-of-the-following-two-statements
Thanks for this informative blog
ReplyDeleteTop 5 Data science training in chennai
Data science training in chennai
Data science training in velachery
Data science training in OMR
Best Data science training in chennai
Data science training course content
Data science certification in chennai
Data science courses in chennai
Data science training institute in chennai
Data science online course
Data science with python training in chennai
Data science with R training in chennai
Thank you for your sharing and I want to more updates for my research..
ReplyDeleteAppium Training in Chennai
Appium Certification in Chennai
Pega Training in Chennai
Tableau Training in Chennai
Advanced Excel Training in Chennai
Spark Training in Chennai
Primavera Training in Chennai
Unix Training in Chennai
Power BI Training in Chennai
Corporate Training in Chennai
Placement Training in Chennai
Thank you for excellent article.Great information for new guy like antimalware service executable
ReplyDeleteThanks for sharing useful information. I learned something new from your bog. Its very interesting and informative. keep updating. If you are looking for any Big Data related information, please visit our website Big Data training institute in Bangalore.
ReplyDeleteGet Computer Science Assignment Help online visit NeedAssignmentHelp provide the best computer science assignment 100% Trusted & Secure.24/7 Live Chat, On-time Delivery, Low Price. Order Now!
ReplyDeleteComputer Science Assignment Help
I have been reading for the past two days about your blogs and topics, still on fetching! Wondering about your words on each line was massively effective.
ReplyDeletephp online training in chennai
php programming center in chennai
php class in chennnai
php certification course
php developer training institution chennai
php training in chennnai
php mysql course in chennai
php institute in chennnai
php course in chennnai
php training with placement in chennnai
php developer course
Nice post. Thanks for sharing! I want people to know just how good this information is in your article. It’s interesting content and Great work.
ReplyDeleteappium online training
appium training centres in chennai
best appium training institute in chennnai
apppium course
mobile appium in chennnai
mobile training in chennnai
appium training institute in chennnai
ReplyDeleteAmazing Post. keep update more information.
Selenium Training in Chennai
Selenium Training in Bangalore
Selenium Training in Coimbatore
Selenium Course in Bangalore
Best Selenium Training in Bangalore
Selenium training in marathahalli
Selenium training in Btm
Ethical Hacking Course in Bangalore
Tally Course in Chennai
Amazing Post. keep update more information.
ReplyDeleteAviation Academy in Chennai
Air Hostess Training in Chennai
Airport Management Courses in Chennai
Ground Staff Training in Chennai
Aviation Courses in Chennai
Air Hostess Training Institute in Chennai
Airline Courses in Chennai
Airport Ground Staff Training in Chennai
An impressive share! I have just forwarded this onto a co-worker who was conducting a little homework on this. And he in fact bought me lunch due to the fact that I stumbled upon it for him... lol. Read more So let me reword this.... Thanks for the meal!! But yeah, thanks for spending time to talk about this topic here on your website.
ReplyDeleteThanks for all the tips mentioned in this article! it’s always good to read things you have heard before and are implementing, but from a different perspective, always pick up some extra bits of information. Visit@
ReplyDeleteQuickBooks Support
norton.com/setup
This facet of requests for market access, high-speed Internet notification to the trading platform can be capture with snapshots to keep track of all changes in the second. stock market
ReplyDeleteI appreciate the diligence and professionalism in your write-up. I heartily thank you for sharing this instructive blog. Web Designing Course Training in Chennai | Web Designing Course Training in annanagar | Web Designing Course Training in omr | Web Designing Course Training in porur | Web Designing Course Training in tambaram | Web Designing Course Training in velachery
ReplyDeleteAmazing Post. keep update more information. i really eno to read this.
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
It is important for history coursework writing service students to seek History Essay Writing Services from a reputable history research paper service provider for their custom history paper writing help services.
ReplyDeleteThe development of artificial intelligence (AI) has propelled more programming architects, information scientists, and different experts to investigate the plausibility of a vocation in machine learning. Notwithstanding, a few newcomers will in general spotlight a lot on hypothesis and insufficient on commonsense application. machine learning projects for final year In case you will succeed, you have to begin building machine learning projects in the near future.
ReplyDeleteProjects assist you with improving your applied ML skills rapidly while allowing you to investigate an intriguing point. Furthermore, you can include projects into your portfolio, making it simpler to get a vocation, discover cool profession openings, and Final Year Project Centers in Chennai even arrange a more significant compensation.
Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account.
ROWE ROWE
ReplyDeleteROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ReplyDeleteROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
ROWE ROWE
Very interesting blog. Many blogs I see these days do not really provide anything that attracts others, but believe me the way you interact is literally awesome.You can also check my articles as well.
ReplyDeleteSecurity Guard License
Ontario Security License
Security License Ontario
Security License
Thank you..
Keep it up and update more valuable information like this. If you need website designing and web development services in the best price in Delhi, visit Ogen Infosystem and get website in your budget as you need.
ReplyDeleteWebsite Designing Company
Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
ReplyDeleteData Science Course
Water bodies are the main source of transportation for international freight forwarding. Due to this, sea freight company in Delhi,
ReplyDeletevisit
Freight Forwarder in Vietnam
Shipping Company In India
visit here
ReplyDeleteiso certification in delhi
iso certification in noida
iso certification in gurgaon
iso certification in faridabad
Nice post, I like to read this blog. It is very interesting to read.
ReplyDeletemachine learning in artificial intelligence
what is reactjs used for
amazon web servers
angularjs development company
aws interview questions and answers for freshers pdf
Mua vé máy bay tại Aivivu và tham khảo
ReplyDeletevé máy bay tết
ve may bay di my gia re
mua vé máy bay đi Pháp
vé máy bay từ việt nam sang hàn quốc bao nhiêu tiền
giá vé khứ hồi việt nam nhật bản
vé máy bay đi Anh quốc
Given below are some prominent benefits you can enjoy if you opt for data science training. data science course syllabus
ReplyDeleteI usually make video for youtube instead of such boring article and buy youtube likes from this site https://soclikes.com/, but it is your business
ReplyDeleteExcellent post...! It is a very great idea and unique content. Thank you so much...
ReplyDeleteOracle Training in Chennai
Oracle Training in Coimbatore
Oracle Training in Bangalore
Oracle DBA Training in Chennai
Oracle DBA Training Institute in Chennai
Power BI Training in Chennai
Appium Training in Chennai
This is additionally a generally excellent post which I truly delighted in perusing. It isn't each day that I have the likelihood to see something like this..
ReplyDeletedata science course in noida
Đặt mua vé máy bay tại Aivivu, tham khảo
ReplyDeletevé máy bay đi Mỹ giá rẻ
vé máy bay tết giá rẻ
giá vé máy bay eva đi canada
vé máy bay đi Pháp giá bao nhiêu
vé máy bay đi anh bao nhiêu tiền
web đặt vé máy bay giá rẻ
vé máy bay từ Hà nội đi San Francisco
vé máy bay đi Los Angeles bao nhiêu tiền
combo du lịch phú quốc vinpearl
combo resort vinpearl nha trang
Good information you shared. keep posting.
ReplyDeletedata scientist training in aurangabad
This Blog is very useful and informative.
ReplyDeletebest data science courses
With endless books and articles coming up to offer entryway to bring in cash online field and confounding peruser much more on the real method of bringing in cash, data scientist course
ReplyDeleteAs always your articles do inspire me. Every single detail you have posted was great.
ReplyDeletedata science courses in delhi