{"id":2929,"date":"2021-07-14T18:13:14","date_gmt":"2021-07-14T15:13:14","guid":{"rendered":"https:\/\/demensdeum.com\/blog\/?p=2929"},"modified":"2024-12-16T22:32:24","modified_gmt":"2024-12-16T19:32:24","slug":"writing-stuff-in-assembly-for-sega-genesis-1","status":"publish","type":"post","link":"https:\/\/demensdeum.com\/blog\/hi\/2021\/07\/14\/writing-stuff-in-assembly-for-sega-genesis-1\/","title":{"rendered":"Writing Assembler for Sega Genesis #1"},"content":{"rendered":"<p>The first article dedicated to writing games for the classic Sega Genesis console in Motorola 68000 Assembler.<\/p>\n<p>Let&#8217;s write the simplest infinite loop for Sega. For this we will need: assembler, emulator with disassembler, favorite text editor, basic understanding of Sega ROM structure.<\/p>\n<p> For development, I use my own assembler\/Dizassembler GEN68KRYBABY: <\/p>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/gen68krybaby\/\" target=\"_blank\" rel=\"noopener\">https:\/\/gitlab.com\/demensdeum\/gen68krybaby\/<\/a><\/ p><\/p>\n<p>The tool is developed in Python 3, for assembly a file with the extension .asm or .gen68KryBabyDisasm is fed to the input, the output is a file with the extension .gen68KryBabyAsm.bin, which can be run in an emulator or on a real console (be careful, move away, the console may explode!)<\/p>\n<p>ROM disassembly is also supported, for this you need to supply a ROM file to the input, without the .asm or .gen68KryBabyDisasm extensions. Opcode support will increase or decrease depending on my interest in the topic, the participation of contributors.<\/p>\n<h3>Structure<\/h3>\n<p>The Sega ROM header takes up the first 512 bytes. It contains information about the game, the title, supported peripherals, checksum, and other system flags. I assume that without the header, the console won&#8217;t even look at the ROM, thinking that it&#8217;s invalid, like &#8220;what are you giving me here?&#8221;<\/p>\n<p>After the header comes the Reset subroutine\/subprogram, with it the m68K processor starts working. Okay, now it&#8217;s a small matter &#8211; find the opcodes (operation codes), namely, doing nothing(!) and jumping to the subroutine at the address in memory. Googling, you can find the NOP opcode, which does nothing, and the JSR opcode, which performs an unconditional jump to the argument address, that is, it simply moves the carriage where we ask it to, without any whims.<\/p>\n<h3>Putting it all together<\/h3>\n<p>The title donor for the ROM was one of the games in the Beta version, currently written as hex data.<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>\n 00 ff 2b 52 00 00 02 00 00 00 49 90 00 00 49 90 00 00 49 90 00...\u0438 \u0442.\u0434. <\/code><\/pre>\n<p>\u041a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b \u0441\u043e-\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0430\u0431\u0440\u0443\u0442\u0438\u043d\u044b Reset\/EntryPoint \u0432 512 (0x200) \u0431\u0430\u0439\u0442\u0435, NOP, \u0432\u043e\u0437\u0432\u0440\u0430\u0442 \u043a\u0430\u0440\u0435\u0442\u043a\u0438 \u043a 0x00000200, \u0442\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u043c \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0446\u0438\u043a\u043b.<\/p>\n<p>\u0410\u0441\u0441\u0435\u043c\u0431\u043b\u0435\u0440\u043d\u044b\u0439 \u043a\u043e\u0434 \u0441\u0430\u0431\u0440\u0443\u0442\u0438\u043d\u044b Reset\/EntryPoint:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code>    NOP\n    NOP\n    NOP \n    NOP\n    NOP\n    JSR 0x00000200  \n<\/code><\/pre>\n<\/div>\n<p>Full example with rom title:<\/p>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/segagenesisamples\/-\/blob\/main\/1InfiniteLoop\/1infiniteloop.asm\" rel=\"noopener\" target=\"_blank\">https:\/\/gitlab.com \/demensdeum\/segagenesisamples\/-\/blob\/main\/1InfiniteLoop\/1infiniteloop.asm<\/a><\/p>\n<p>Next we collect:<\/p>\n<div class=\"hcb_wrap\">\n<pre class=\"prism line-numbers lang-unknown\" data-lang=\"unknown\"><code><\/p>\n<p>\u0417\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u043c \u0440\u043e\u043c 1infiniteloop.asm.gen68KryBabyAsm.bin \u0432 \u0440\u0435\u0436\u0438\u043c\u0435 \u0434\u0435\u0431\u0430\u0433\u0433\u0435\u0440\u0430 \u044d\u043c\u0443\u043b\u044f\u0442\u043e\u0440\u0430 Exodus\/Gens, \u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0447\u0442\u043e m68K \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 NOP, \u0438 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u043d\u043e \u043f\u0440\u044b\u0433\u0430\u0435\u0442 \u043a EntryPoint \u0432 0x200 \u043d\u0430 JSR<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2933\" src=\"https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2021\/07\/JSR.jpg\" alt=\"\" width=\"804\" height=\"652\" srcset=\"https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2021\/07\/JSR.jpg 804w, https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2021\/07\/JSR-300x243.jpg 300w, https:\/\/demensdeum.com\/blog\/wp-content\/uploads\/2021\/07\/JSR-768x623.jpg 768w\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" \/><\/p>\n<p>\u0417\u0434\u0435\u0441\u044c \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0421\u043e\u043d\u0438\u043a \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0449\u0438\u0439 V, \u043d\u043e \u043e\u043d \u0443\u0435\u0445\u0430\u043b \u043d\u0430 <a href=\"https:\/\/www.wacken.com\" target=\"_blank\" rel=\"noopener\">\u0412\u0430\u043a\u0435\u043d<\/a>.<\/p>\n<h3>\u0421\u0441\u044b\u043b\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/gen68krybaby\/\" target=\"_blank\" rel=\"noopener\">https:\/\/gitlab.com\/demensdeum\/gen68krybaby\/<\/a><\/p>\n<p><a href=\"https:\/\/gitlab.com\/demensdeum\/segagenesissamples\" target=\"_blank\" rel=\"noopener\">https:\/\/gitlab.com\/demensdeum\/segagenesissamples<\/a><\/p>\n<p><a href=\"https:\/\/www.exodusemulator.com\/downloads\/release-archive\" target=\"_blank\" rel=\"noopener\">https:\/\/www.exodusemulator.com\/downloads\/release-archive<\/a><\/p>\n<h3>\u0418\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0438<\/h3>\n<p><a href=\"https:\/\/www.youtube.com\/watch?v=mrKFbZGTnNk\" target=\"_blank\" rel=\"noopener\">ROM Hacking Demo &#8211; Genesis and SNES games in 480i<\/a><\/p>\n<p><a href=\"http:\/\/68k.hax.com\/\" target=\"_blank\" rel=\"noopener\">http:\/\/68k.hax.com\/<\/a><\/p>\n<p><a href=\"https:\/\/www.chibiakumas.com\/68000\/genesis.php\" target=\"_blank\" rel=\"noopener\">https:\/\/www.chibiakumas.com\/68000\/genesis.php<\/a><\/p>\n<p><a href=\"https:\/\/plutiedev.com\/rom-header\" target=\"_blank\" rel=\"noopener\">https:\/\/plutiedev.com\/rom-header<\/a><\/p>\n<p><a href=\"https:\/\/blog.bigevilcorporation.co.uk\/2012\/02\/28\/sega-megadrive-1-getting-started\/\" target=\"_blank\" rel=\"noopener\">https:\/\/blog.bigevilcorporation.co.uk\/2012\/02\/28\/sega-megadrive-1-getting-started\/<\/a><\/p>\n<p><a href=\"https:\/\/opensource.apple.com\/source\/cctools\/cctools-836\/as\/m68k-opcode.h.auto.html\" target=\"_blank\" rel=\"noopener\">https:\/\/opensource.apple.com\/source\/cctools\/cctools-836\/as\/m68k-opcode.h.auto.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The first article dedicated to writing games for the classic Sega Genesis console in Motorola 68000 Assembler. Let&#8217;s write the simplest infinite loop for Sega. For this we will need: assembler, emulator with disassembler, favorite text editor, basic understanding of Sega ROM structure. For development, I use my own assembler\/Dizassembler GEN68KRYBABY: https:\/\/gitlab.com\/demensdeum\/gen68krybaby\/ The tool is<a class=\"more-link\" href=\"https:\/\/demensdeum.com\/blog\/hi\/2021\/07\/14\/writing-stuff-in-assembly-for-sega-genesis-1\/\">Continue reading <span class=\"screen-reader-text\">&#8220;Writing Assembler for Sega Genesis #1&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[61,52],"tags":[165,166,173,172],"class_list":["post-2929","post","type-post","status-publish","format-standard","hentry","category-techie","category-tutorials","tag-asm","tag-assembly","tag-m68k","tag-roms","entry"],"translation":{"provider":"WPGlobus","version":"3.0.2","language":"hi","enabled_languages":["en","ru","zh","de","fr","ja","pt","hi"],"languages":{"en":{"title":true,"content":true,"excerpt":false},"ru":{"title":true,"content":true,"excerpt":false},"zh":{"title":true,"content":true,"excerpt":false},"de":{"title":true,"content":true,"excerpt":false},"fr":{"title":true,"content":true,"excerpt":false},"ja":{"title":true,"content":true,"excerpt":false},"pt":{"title":true,"content":true,"excerpt":false},"hi":{"title":false,"content":false,"excerpt":false}}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2929","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/comments?post=2929"}],"version-history":[{"count":25,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2929\/revisions"}],"predecessor-version":[{"id":3898,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/posts\/2929\/revisions\/3898"}],"wp:attachment":[{"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/media?parent=2929"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/categories?post=2929"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/demensdeum.com\/blog\/hi\/wp-json\/wp\/v2\/tags?post=2929"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}